103636: [Atcoder]ABC363 G - Dynamic Scheduling
Description
Score : $675$ points
Problem Statement
You are given two sequences of length $N$: $D=(D_1, D_2, \dots, D_N)$ and $P=(P_1, P_2, \dots, P_N)$.
Process $Q$ queries in the order they are given. Each query is given in the following format:
c x y
: Change $D_c$ to $x$ and $P_c$ to $y$. Then, solve the following problem and print the answer.
There are $N$ jobs numbered $1$ to $N$.
Starting from today (consider this as day $1$), you will choose and complete one job per day for $N$ days.
If you complete job $i$ on or before day $D_i$, you will receive a reward of $P_i$. (If you do not complete it by day $D_i$, you get nothing.)
Find the maximum total reward you can achieve by choosing the optimal order of completing the jobs.
Constraints
- $1 \leq N \leq 10^5$
- $1 \leq Q \leq 10^5$
- $1 \leq D_i \leq N$
- $1 \leq P_i \leq 10^9$
- $1 \leq c \leq N$
- $1 \leq x \leq N$
- $1 \leq y \leq 10^9$
- All input values are integers.
Input
The input is given from Standard Input in the following format. Here, $\mathrm{query}_i$ denotes the $i$-th query.
$N$ $Q$ $D_1$ $D_2$ $\dots$ $D_N$ $P_1$ $P_2$ $\dots$ $P_N$ $\mathrm{query}_1$ $\mathrm{query}_2$ $\vdots$ $\mathrm{query}_Q$
Each query is given in the following format.
$c$ $x$ $y$
Output
Print $Q$ lines. The $i$-th line should contain the answer to the $i$-th query.
Sample Input 1
3 2 1 2 3 3 6 3 3 1 4 2 3 9
Sample Output 1
10 13
The first query is as follows:
- Update $D_3$ to $1$ and $P_3$ to $4$. Now, $D = (1, 2, 1)$ and $P = (3, 6, 4)$.
- In the subproblem, one optimal procedure is to complete job $3$ on day $1$, job $2$ on day $2$, and job $1$ on day $3$. The total reward is $10$, so print $10$.
The second query is as follows:
- Update $D_2$ to $3$ and $P_2$ to $9$. Now, $D = (1, 3, 1)$ and $P = (3, 9, 4)$.
- In the subproblem, one optimal procedure is to complete job $3$ on day $1$, job $1$ on day $2$, and job $2$ on day $3$. The total reward is $13$, so print $13$.
Sample Input 2
5 1 1 2 3 4 5 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1000000000
Sample Output 2
5000000000
Sample Input 3
10 10 6 2 4 1 5 1 6 6 5 3 45 65 71 52 86 52 48 60 40 98 5 6 5 8 4 34 6 7 83 1 3 21 7 5 85 7 4 51 8 2 81 2 7 54 6 1 5 8 6 30
Sample Output 3
394 379 462 457 459 414 443 479 401 396
Output
得分:675分
问题陈述
给定两个长度为N的序列:D=(D_1, D_2, …, D_N) 和 P=(P_1, P_2, …, P_N)。
按给定的顺序处理Q个查询。每个查询的格式如下:
c x y
:将D_c更改为x,P_c更改为y。然后,解决以下问题并打印答案。
有N个编号为1到N的工作。
从今天开始(视为第1天),你将在N天内每天选择并完成一个工作。
如果你在第D_i天或之前完成工作i,你将获得P_i的奖励。(如果你在第D_i天之后完成,你将一无所获。)
找出通过选择最佳完成工作顺序你可以获得的最大总奖励。
约束条件
- 1 ≤ N ≤ 10^5
- 1 ≤ Q ≤ 10^5
- 1 ≤ D_i ≤ N
- 1 ≤ P_i ≤ 10^9
- 1 ≤ c ≤ N
- 1 ≤ x ≤ N
- 1 ≤ y ≤ 10^9
- 所有输入值都是整数。
输入
输入从标准输入以以下格式给出。这里,query_i表示第i个查询。
N Q D_1 D_2 … D_N P_1 P_2 … P_N query_1 query_2 … query_Q
每个查询的格式如下。
c x y
输出
打印Q行。第i行应包含第i个查询的答案。
示例输入1
3 2 1 2 3 3 6 3 3 1 4 2 3 9
示例输出1
10 13
第一个查询如下:
- 将D_3更新为1,P_3更新为4。现在,D = (1, 2, 1) 和 P = (3, 6, 4)。
- 在子问题中,一个最优过程是在第1天完成工作3,第2天完成工作2,第3天完成工作1。总奖励是10,所以打印10。
第二个查询如下:
- 将D_2更新为3,P_2更新为9。现在,D = (1, 3, 1) 和 P = (3, 9, 4)。
- 在子问题中,一个最优过程是在第1天完成工作3,第2天完成工作1,第3天完成工作2。总奖励是13,所以打印13。
示例输入2
5 1 1 2 3 4 5 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1000000000
示例输出2
5000000000
示例输入3
10 10 6 2 4 1 5 1 6 6 5 3 45 65 71 52 86 52 48 60 40 98 5 6 5 8 4 34 6 7 83 1 3 21 7 5 85 7 4 51 8 2 81 2 7 54 6 1 5