33OJ
登录 注册

#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 nn items; the ii-th item has price viv_i and cost-performance ratio wiw_i. At the beginning, Little Y buys all items with the maximum cost-performance ratio (if there are several, she buys all of them). Then mm events happen one after another, and the ii-th event (1≤i≤m1 \leq i \leq m) is one of the following two types:

  1. A new item with price xix_i and cost-performance ratio yiy_i is added, and its index is n+in+i;
  2. The cost-performance ratio of the item with index xix_i is changed to yiy_i.

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 LL 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 ≥L\ge L.

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 n,mn, m, the number of items and the number of events.

In the following nn lines, the ii-th line contains two integers vi,wiv_i, w_i.

In the following mm lines, the ii-th line contains three integers oi,xi,yio_i, x_i, y_i, where oi=1o_i = 1 means event ii adds an item, and oi=2o_i = 2 means event ii changes a cost-performance ratio.

Output Format

Output mm lines in total. The ii-th line contains one integer, Little Y's total spending after event ii.

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 55 and 66 have the highest cost-performance ratio, so the items bought by Little Y are {5,6}\{5, 6\}.

In event 11, the cost-performance ratio of item 55 is changed to 44. Now w4≥w5w_4 \geq w_5, so Little Y buys item 44, while the other items remain unbought. Now the items bought by Little Y are {4,5,6}\{4, 5, 6\}.

In event 22, a new item is added with index 6+2=86+2=8, but its cost-performance ratio is only 33, so Little Y does not buy it.

In event 33, the cost-performance ratio of item 88 is changed to 44; Little Y then buys item 88, so now all the items she has bought are {4,5,6,8}\{4, 5, 6, 8\}.

In event 44, the cost-performance ratio of item 55 is changed to 22, and finally all the items bought by Little Y are {2,3,4,5,6,8}\{2, 3, 4, 5, 6, 8\}.

Constraints

Subtask Special property Points
11 n,m≤3000n, m \leq 3000 6060
22 wi,yi≤10w_i, y_i \leq 10 1515
33 — 2525

For all test data: it is guaranteed that 1≤n≤2×1051 \leq n \leq 2\times 10^5, 1≤m≤2×1051 \leq m \leq 2\times 10^5, 0≤vi,wi,yi≤1090 \leq v_i, w_i, y_i \leq 10^9, oi∈{1,2}o_i \in \{1, 2\}. If oi=1o_i = 1, then 0≤xi≤1090 \leq x_i \leq 10^9; otherwise it is guaranteed that the item with index xix_i already exists.

Translated by QwenWork