#abc287g. G - Balance Update Query

G - Balance Update Query

Score : 600600 points

问题描述

Takahashi 拥有 1010010^{100} 张每种类型的卡片,共有 NN 种类型。最初,第 ii 种类型的卡片的得分和限额分别设置为 aia_ibib_i

接下来将按照以下格式接收并处理 QQ 个查询请求:

  • 1 x y: 将第 xx 种类型的卡片得分设置为 yy
  • 2 x y: 将第 xx 种类型的卡片限额设置为 yy
  • 3 x: 如果在满足以下条件下可以选择 xx 张卡片,则输出所选卡片得分的最大可能总和;否则输出 -1
    • 每种类型的卡片选择数量不超过其限额。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

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.

Sample Input 1

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

Sample Output 1

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.

update @ 2024/3/10 12:00:48

}