atcoder#ABC287G. [ABC287G] Balance Update Query

[ABC287G] Balance Update Query

Score : 600600 points

Problem Statement

Takahashi has 1010010^{100} cards of each of NN kinds. Initially, the score and quota of the ii-th kind of card are set to aia_i and bib_i, respectively.

Given QQ queries in the following formats, process them in order.

  • 1 x y: set the score of the xx-th kind of card to yy.
  • 2 x y: set the quota of the xx-th kind of card to yy.
  • 3 x: if one can choose xx cards subject to the following condition, print the maximum possible sum of the scores of the chosen cards; print -1 otherwise.- The number of chosen cards of each kind does not exceed its quota.
  • The number of chosen cards of each kind does not exceed its quota.

Constraints

  • 1N,Q2×1051 \leq N,Q \leq 2 \times 10^5
  • 0ai1090 \leq a_i \leq 10^9
  • 0bi1040 \leq b_i \leq 10^4
  • For each query of the 11-st kind, 1xN1 \leq x \leq N and 0y1090 \leq y \leq 10^9.
  • For each query of the 22-nd kind, 1xN1 \leq x \leq N and 0y1040 \leq y \leq 10^4.
  • For each query of the 33-rd kind, 1x1091 \leq x \leq 10^9.
  • There is at least one query of the 33-rd kind.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where queryi\mathrm{query}_i denotes the ii-th query:

NN

a1a_1 b1b_1

\vdots

aNa_N bNb_N

QQ

query1\mathrm{query}_1

\vdots

queryQ\mathrm{query}_Q

Output

Print MM lines, where MM is the number of queries of the 33-rd kind. The ii-th line should contain the response to the ii-th such query.

3
1 1
2 2
3 3
7
3 4
1 1 10
3 4
2 1 0
2 3 0
3 4
3 2
11
19
-1
4

For the first query of the 33-rd kind, you can choose one card of the 22-nd kind and three cards of the 33-rd kind for a total score of 1111, which is the maximum. For the second such query, you can choose one card of the 11-st kind and three cards of the 33-rd kind for a total score of 1919, which is the maximum. For the third such query, you cannot choose four cards, so -1 should be printed. For the fourth such query, you can choose two cards of the 22-nd kind for a total score of 44, which is the maximum.