102876: [AtCoder]ABC287 G - Balance Update Query
Description
Score : $600$ points
Problem Statement
Takahashi has $10^{100}$ cards of each of $N$ kinds. Initially, the score and quota of the $i$-th kind of card are set to $a_i$ and $b_i$, respectively.
Given $Q$ queries in the following formats, process them in order.
1 x y
: set the score of the $x$-th kind of card to $y$.2 x y
: set the quota of the $x$-th kind of card to $y$.3 x
: if one can choose $x$ 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
- $1 \leq N,Q \leq 2 \times 10^5$
- $0 \leq a_i \leq 10^9$
- $0 \leq b_i \leq 10^4$
- For each query of the $1$-st kind, $1 \leq x \leq N$ and $0 \leq y \leq 10^9$.
- For each query of the $2$-nd kind, $1 \leq x \leq N$ and $0 \leq y \leq 10^4$.
- For each query of the $3$-rd kind, $1 \leq x \leq 10^9$.
- There is at least one query of the $3$-rd kind.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where $\mathrm{query}_i$ denotes the $i$-th query:
$N$ $a_1$ $b_1$ $\vdots$ $a_N$ $b_N$ $Q$ $\mathrm{query}_1$ $\vdots$ $\mathrm{query}_Q$
Output
Print $M$ lines, where $M$ is the number of queries of the $3$-rd kind.
The $i$-th line should contain the response to the $i$-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 $3$-rd kind, you can choose one card of the $2$-nd kind and three cards of the $3$-rd kind for a total score of $11$, which is the maximum.
For the second such query, you can choose one card of the $1$-st kind and three cards of the $3$-rd kind for a total score of $19$, 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 $2$-nd kind for a total score of $4$, which is the maximum.
Input
题意翻译
有 $n$ 种卡片, 每种卡片有两种属性: 价值$A_i$ 和数目 $B_i$, 要求支持 $3$ 种操作 * 读入$(1, x, y)$, 将$A_x$ 的数值改为 $y$。 * 读入$(2, x, y)$, 将$B_x$ 的数值改为 $y$。 * 读入$(3, x)$, 输出在所有卡片中选择$x$张卡片的最大价值, 若$\sum\limits_{i=1}^{n}B_i <x$, 则输出$-1$Output
分数:600分
问题描述
高桥持有$N$种各$10^{100}$张的卡。初始时,第$i$种卡的分数和配额分别为$a_i$和$b_i$。
根据以下格式的$Q$个查询,按顺序处理它们。
1 x y
:将第$x$种卡的分数设置为$y$。2 x y
:将第$x$种卡的配额设置为$y$。3 x
:如果可以选择满足以下条件的$x$张卡,则打印所选卡的分数之和的最大可能值;否则打印-1
。- 每种卡所选的数量不超过其配额。
约束
- $1 \leq N,Q \leq 2 \times 10^5$
- $0 \leq a_i \leq 10^9$
- $0 \leq b_i \leq 10^4$
- 对于每种类型的第1个查询,$1 \leq x \leq N$,$0 \leq y \leq 10^9$。
- 对于每种类型的第2个查询,$1 \leq x \leq N$,$0 \leq y \leq 10^4$。
- 对于每种类型的第3个查询,$1 \leq x \leq 10^9$。
- 至少有一个第3种类型的查询。
- 输入中的所有值都是整数。
输入
输入以以下格式从标准输入给出,其中$\mathrm{query}_i$表示第$i$个查询:
$N$ $a_1$ $b_1$ $\vdots$ $a_N$ $b_N$ $Q$ $\mathrm{query}_1$ $\vdots$ $\mathrm{query}_Q$
输出
打印$M$行,其中$M$是第3种类型的查询的数量。
第$i$行应包含对第$i$个此类查询的响应。
样例输入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
样例输出1
11 19 -1 4
对于第3种类型的第一个查询,你可以选择第2种卡1张和第3种卡3张,总分为11,这是最大的。
对于第二个此类查询,你可以选择第1种卡1张和第3种卡3张,总分为19,这是最大的。
对于第三个此类查询,你不能选择4张卡,所以应打印-1
。
对于第四个此类查询,你可以选择第2种卡2张,总分为4,这是最大的。