Store shopping
Title Description
Small K continued his journey, and then he went into a small shop. This store has the n- the n-th commodity, in this small K store in a circle, so he determined a value to each item w_i w i , each product also has a price P_i the p- i yuan.
K shopping small way something special, he will be shopping in several rounds, each round he would choose to choose the highest value goods from his current ability to pay for an item to buy a (if there is the same, the preferred low prices to buy goods ), so each round he will buy a product (the number of each product are an infinite number of) until he can not buy any merchandise.
Now small K wanted to know, assuming he has a k k dollars, then he will buy the sum of the value of the number of commodities. With, mood environmental economic policies of market demand, shopkeepers and small K changes, small K for each product and the value fixed by the owner for each commodity prices are set by the change, while the small K will occasionally ask you, you were his answer.
Input Format
The first line of two positive integers n-, m n- , m, represents the number of commodities, and the number of inquiry and modification.
Next, n- n-lines of two positive integers W_i, P_i W i , P i , denotes the i value and the price of the items i.
Subsequently m m rows, each of the operation or behavior of a query, in the following format:
-
1 xwp, represents the first x value of x items changed w w, the price changed to the p- the p-;
-
2 2 k, indicating an inquiry k sum of k dollars worth of goods are bought.
Output Format
Total number of lines, each row corresponds to a query sequence
Sample
Sample input 1
3 3
1 1
2 2
3 3
2 10
1 1 6 6
2 10
Sample output 1
10
9
Data range and tips
Test point number | Restrictions |
---|---|
1-2 | n,m,k \le 2000n,m,k≤2000 |
3-4 | Modify operation does not exist |
5-10 | n, m \ 100000 the n , m ≤ 1 0 0 0 0 0 |
对于100%的数据, $ 1 \ k, m \ The 100000.1 \ the w_i, p_i, w, k, k \ 10 ^ 9,1 \ X \ k 1 ≤ n , m ≤ 1 0 0 0 0 0 , 1 ≤ w in , night in , w , k , k ≤ 1 0, 9 , 1 ≤ x ≤ n $
source
CSP2019 Changzhou training 11-1
Solution
K a purchase can be found less than half.
So we consider the violent process simulation to buy, need support: Find p <= k largest items w, adding, deleting items.
W consider discrete construction segment tree, each leaf node to open a deposit mutiset p.
Line tree on the minimum maintenance interval p of each half to find the tree line.
Note: 1. The complete segment tree discrete achievements, query, modify are 1 ~ tot
2.mutiset then delete the value is to delete all, if only need to delete a iterator