Mock CCC '18 Contest 3 S5 - A Rage Tree Problem

View as PDF

Points: 20 (partial)
Time limit: 1.8s
Java 3.0s
Memory limit: 1G

Problem type

Richard has quit competitive programming and has opened an ice cream stand. Help him run his stand! Here are the operations to support:

ADD K P - Richard is now willing to sell more ice cream cones, each at dollars.

ADDRANGE A B - Richard is now willing to sell one more ice cream cone for each price between and , inclusive.

BUYAMT Q - Nick has dollars, and buys the maximum number of cones he can, starting from cheapest to most expensive. Report how many cones Nick buys.

BUYLOW L - Nick buys the cheapest cones Richard is selling, or all of them if Richard is selling fewer than of them. Report the total cost of the cones bought.

BUYHIGH L - Nick buys the most expensive cones Richard is selling, or all of them if Richard is selling fewer than of them. Report the total cost of the cones bought.

COST L - Report the cost of the th cheapest cone. If there are fewer than cones, return -1.

NUMCONES - Report how many cones Richard is currently selling.

TOTALCOST - Report the total cost of every cone that Richard is currently selling.

Constraints

For 2 marks, .

For 3 additional marks, there will be no BUYLOW, BUYHIGH, or COST operations.

For 4 additional marks, there will be no COST operations.

Input Specification

The first line will contain a single positive integer , the number of operations to support. will be at most .

Each of the next lines will contain information for one of the operations, as shown above.

As written above, , , , and .

Output Specification

For every operation that demands reporting a value, print out the desired value.

Sample Input

8
COST 1
NUMCONES
TOTALCOST

Sample Output

2
7
13
4
6
25

• commented on Feb. 10, 2018, 8:26 p.m. edited

Thanks to PlasmaVortex I now understand that the queries are also updates.

PS: Who the hell is stevenmai_uts and why do you have my name?

Edit: I also realized my comment below is number 6969

• commented on April 24, 2018, 10:32 a.m.

nice.

• commented on Feb. 9, 2018, 2:44 p.m.

Is the test case correct? Shouldn't BUYLOW(2) = 3, COST(1) = 1, NUMCONES = 12, and TOTALCOST = 48?