#P14962. [LBA-OI R2 A] 一次买够
[LBA-OI R2 A] 一次买够
Background
A light warm-up problem.
Problem Description
Little Y is very rich, so she can buy everything she wants.
Today she comes to a shop to go shopping. The shop has items; the -th item has price and cost-performance ratio . At the beginning, Little Y buys all items with the maximum cost-performance ratio (if there are several, she buys all of them). Then events happen one after another, and the -th event () is one of the following two types:
- A new item with price and cost-performance ratio is added, and its index is ;
- The cost-performance ratio of the item with index is changed to .
Note that once Little Y has bought an item, she will not sell it later even if its cost-performance ratio decreases.
After each event, let be the minimum cost-performance ratio among the items Little Y has already bought; at this moment Little Y buys all unbought items whose cost-performance ratio is .
As Little Y's life assistant, you need to compute Little Y's total spending after each event.
Input Format
The first line contains two integers , the number of items and the number of events.
In the following lines, the -th line contains two integers .
In the following lines, the -th line contains three integers , where means event adds an item, and means event changes a cost-performance ratio.
Output Format
Output lines in total. The -th line contains one integer, Little Y's total spending after event .
6 4
1 1
1 2
1 3
1 4
1 5
1 5
2 5 4
1 10 3
2 8 4
2 5 2
3
3
13
15
5 5
11 4
13 6
14 3
20 8
0 5
2 4 5
2 5 0
2 4 10
1 12 2
2 1 0
33
58
58
70
70
Hint
Sample Explanation 1
Initially, items and have the highest cost-performance ratio, so the items bought by Little Y are .
In event , the cost-performance ratio of item is changed to . Now , so Little Y buys item , while the other items remain unbought. Now the items bought by Little Y are .
In event , a new item is added with index , but its cost-performance ratio is only , so Little Y does not buy it.
In event , the cost-performance ratio of item is changed to ; Little Y then buys item , so now all the items she has bought are .
In event , the cost-performance ratio of item is changed to , and finally all the items bought by Little Y are .
Constraints
| Subtask | Special property | Points |
|---|---|---|
| — |
For all test data: it is guaranteed that , , , . If , then ; otherwise it is guaranteed that the item with index already exists.
Translated by QwenWork