CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » October Long Contest 2011 » The Baking Business

The Baking Business

Problem code: BAKE

  • All Submissions

All submissions for this problem are available.

The chef has turned into an entrepreneur running a bakery business. He is selling products like Biscuit, Bread etc which are packaged in various sizes. He is selling the products in the various cities of different provinces which are further sub-categorized into various regions. He maintains the data about the sex and age of all his customers along with the time of purchase. For running his business successfully, he requires a business intelligence tool to get analysis reports of sales aggregates based on various parameters so that he can run his business efficiently.

Input

There are 10 different products which will be packaged in maximum 3 different sizes. There are 10 different provinces and each province can have upto 20 cities which can be further divided in at maximum 5 different regions.

The first line of the input contains the total number S (<= 100000) of input lines. Each input line either begins with character 'I' (which stands for sale input)or 'Q' (which stands for query). The format of sale input is

I product_id[.size_id] province[.city_id[.region_id]] M/F age units_sold

This line contains details of individual sale vis-vis product details, location detail, customer sex and age (from 1 to 90, including the limit) separated by spaces in the following format. The product details e.g 6.2 which means the product with code 6 and size id 2. Next will be location like 8.18.4 which means the 8th province, in the 4th region of the city with code 18. Then the sex of the customer either 'M' or 'F' and age from 1 to 90, including the limits. Note that all the codes/id's will begin from 0. Note that parts in the square brackets in the given format are optional because some specific information about the sale is missing due to practical reasons. The units_sold will be less than or equal to 100.

Similarly, the format for a query line is

Q product_id[.size_id] province[.city_id[.region_id]] M/F start_age[-end_age]

This queries the total number of product units sold which falls under that specification. In case the optional parts are missing, then it means that the query is asking for the total units sold falling under all the sub-specifications under that. For the age parameter, if the end_age is missing then the query is only for the unit sold to customer of age equal to start_age, otherwise for all the customers falling in the range. A special product_id is -1 which means all the products and similarly -1 for province means all the provinces. This id will never be qualified with sub-specifications.

Output

For each query line specification output the total units sold which falls under that on a separate line. The answer should be based on the input given before the line and not on the input which will appear in the subsequent lines.

Example

Input:
6
I 1.1 2.1 F 70 22
I 1 4.1 F 37 73
Q 1.1 2 F 10-90
I 2 4.2 M 63 24
Q 1 -1 F 30-70
Q 2 4.1 F 37

Output:
22
95
0

Sample I/O Explanation

For the first query at the 4th line of input, only the first input is relevant as the the second input has location specification as 4.1 whereas in the query it is 2. Location specification 2 includes all the cities in the province 2 such as 2.1 whic is the case with the first input. Hence the solution is 22.

For the query specification on the second last line, it only includes the first 2 inputs as the third input mismatches with the query w.r.t the location and sex specification.

For the third query, it does not match with any input, hence the answer is 0.


Author: nomind
Date Added: 22-08-2011
Time Limit: 1 - 10 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

feels like we have to create

biraj_patel @ 1 Oct 2011 07:01 PM
feels like we have to create mini working version of SQL lol.......

whats the ouput of following

gunjanbansal @ 3 Oct 2011 12:49 PM
whats the ouput of following lines: I 1 2.1 F 70 22 Q 1.1 2 F 70 Meaning we know which product id was sold, but not its size. But the query is with size. I think it should be 22

I hope it is ok to inform

how2code @ 3 Oct 2011 01:09 PM
I hope it is ok to inform according to contest rules, since there is some ambiguity in understanding the question for a split second. @gunjanbansal: My Accepted code prints 0 for your case.

is a

bsrkaditya @ 3 Oct 2011 03:42 PM
is a province.city_id.region_id like 15.21.7 possible? that is how can city_id be 21, when there are only 20 cities?

Are the product_id's and the

pragrame @ 3 Oct 2011 07:51 PM
Are the product_id's and the province_id's in the input 1-based, or 0-based? This would be useful in case I would take product_id input as a single character, instead of a number, so... ?

Really, is the description of

alexfetisov @ 4 Oct 2011 03:01 AM
Really, is the description of size is correct? I mean 6.3 which means the product with code 6 and size id 3 - is possible or not? 3 different sizes and 0 based?

AC with 0 based size and

alexfetisov @ 4 Oct 2011 03:05 AM
AC with 0 based size and ignoring the description

@gunjanbansal The solution

anirban_adm @ 4 Oct 2011 12:20 PM
@gunjanbansal The solution for I 1 2.1 F 70 22 Q 1.1 2 F 70 is 0. All the input codes are 0 based and within the limits as specified in the problem even though examples used to explain are a bit confusing. I will try to get them updated. Thanks for the comments clearing the confusion.

Is not clear what exactly

roorback @ 4 Oct 2011 11:13 PM
Is not clear what exactly happens with optional insertion parameters... If I insert a product with optional size, for example, when I list all products with a specified size should I add also the unknown products? Example: I 1 2.1 F 70 22 Q 1 2.1 F 70 22 <<----- I know, must print 22. Q 1.1 2.1 F 70 22 <<---- Should print 0 or 22?

@roorback I think, that 0

Kokos @ 4 Oct 2011 11:48 PM
@roorback I think, that 0

@admin : Since indexing is 0

sanchit_h @ 5 Oct 2011 11:06 AM
@admin : Since indexing is 0 based, this should mean that the 10 possible products are indexed from 0 to 9 right ? Can the -1 ID also be used for ages ? Is the age range(if specified) inclusive ?

(contd.) I meant inclusive of

sanchit_h @ 5 Oct 2011 12:57 PM
(contd.) I meant inclusive of both the start and end age.

Never mind, got AC.

sanchit_h @ 5 Oct 2011 01:00 PM
Never mind, got AC.

The problem description is

logic_max @ 5 Oct 2011 03:05 PM
The problem description is weak and leaves much to the imagination of the programmer.

is start_age-end_age range

taneja_stud @ 5 Oct 2011 03:43 PM
is start_age-end_age range inclusive or exclusive.....those who got AC can tell which one they used

can someone find the error

taneja_stud @ 5 Oct 2011 03:50 PM
can someone find the error

hey admin.......sry I didnt

taneja_stud @ 5 Oct 2011 04:20 PM
hey admin.......sry I didnt kno the rules......plzz delete my code above

public class Main {

theicebreaker @ 5 Oct 2011 11:37 PM
public class Main { public static void main(String[] args) { int[][][][][][][] data2 = new int[8][4][10][21][8][2][90]; } } Belive it or not this code gives TLE. Multidimentional arrays are a no no in JAVA

i wasted three hours

theicebreaker @ 5 Oct 2011 11:39 PM
i wasted three hours searching fo a reason for TLE of my correct solution JAVA. Now i ll have to code it in C++ again. But atleast I learnt somthing usefull today.

I please for any 'hard' test

Kokos @ 5 Oct 2011 11:43 PM
I please for any 'hard' test case

Is it possible to have a

success @ 6 Oct 2011 04:11 AM
Is it possible to have a query like: Q -1.2 -1.0 M 27-30 or Q 1 2 -1 30

Hey taneja_stud::Its not good

ritesh_gupta @ 6 Oct 2011 05:08 AM
Hey taneja_stud::Its not good to post code in discussion board..And don't know why did u post the code after you solved the problem..If u have any problem with your code..then send email to feedback@codechef.com but plz do not post code..

is the range of city code

dudechandan123 @ 6 Oct 2011 12:02 PM
is the range of city code from 0-19?? or anything else?... and what about other codes?

@dudechandan123 : Its written

svm11 @ 6 Oct 2011 12:54 PM
@dudechandan123 : Its written in the problem statement - "Note that all the codes/id's will begin from 0."

can any one provide me any

allada @ 8 Oct 2011 01:37 AM
can any one provide me any corner test case...im sure that my code was right... donno why it was showing wrong ans

@Admin..........The given

satya_patel @ 9 Oct 2011 05:19 PM
@Admin..........The given time is for one Query/Insertion or for the total S=100000 numbers?

if age_start > end_age, then

gurpreet_09 @ 9 Oct 2011 06:01 PM
if age_start > end_age, then is that we have to find for the range (end_age , age_start) or we must just print 0 for that query??

"Next will be location like

gurpreet_09 @ 9 Oct 2011 11:17 PM
"Next will be location like 8.18.4 which means the 8th province, in the 4th region of the city with code 18".......or does it mean province with code 8 city with code 18 and region with code 4. code/ids are 0 based hence 8.18.4 must mean 9th province 19th city and 5th region.... am i right??

@ all:: Is this query

ritesh_gupta @ 10 Oct 2011 02:41 AM
@ all:: Is this query possible -1.2 1 F 30-70 -1 2.1 F 30-70 ??plz reply

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com