luogu#P7870. 「Wdoi-4」兔已着陆
「Wdoi-4」兔已着陆
Background
Ringo and Seiran are two Moon Rabbits who came from the Lunar Capital to Gensokyo. Since they landed in Gensokyo to investigate, they make a living there by opening a dango shop and selling dango.
To cope with the increasingly booming market, they bought a dango machine from Nitori Kawashiro, which can efficiently produce colorful dango. Dango of different colors have different prices. Because there are many customers every day and they buy a lot of dango, Seiran is always confused about how much a big pile of dango costs.
Seiran came to you and hopes you can tell her the total price of the dango sold each time.
Problem Description
Using the kappa's machine, Seiran can produce dango of many different colors. She found that for a dango with color , its price is . At the same time, the dango machine has a feature: the colors of the produced dango must form a consecutive segment of integers.
To store the produced dango, Seiran uses a structure similar to a "stack". At the start of the day, the stack is empty. Now there are operations of two types:
- : The machine produces dango with colors . Seiran pushes these dango onto the stack in order. That is, she adds to the top of the stack in sequence.
- : A customer wants to buy dango. Seiran will then pop dango from the top of the stack in order and sell them. It is guaranteed that is not greater than the number of dango currently in the stack.
Your task is: for each operation of type , output the total price of these dango.
Input Format
The first line contains an integer , the number of operations.
The next lines each describe one query. The first integer indicates the type of the query: if it is , it is operation ; if it is , it is operation .
- For operation , it is followed by two integers , with the meaning as described above.
- For operation , it is followed by one integer , with the meaning as described above.
Output Format
Output several lines. For each operation of type , output the sum of the prices of the sold dango.
6
1 1 14
2 5
1 14 19
1 1 9
2 8
2 10
60
44
124
Hint
Sample can be found in the attached files .
Constraints
- For the first of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For of the testdata, , , .
Translated by ChatGPT 5