#abc363g. G - Dynamic Scheduling

G - Dynamic Scheduling

Score : 675675 points

问题陈述

你有两个长度为 NN 的序列:D=(D1,D2,,DN)D=(D_1, D_2, \dots, D_N)P=(P1,P2,,PN)P=(P_1, P_2, \dots, P_N)

按照给定的顺序处理 QQ 个查询。每个查询以以下格式给出:

  • c x y: 将 DcD_c 改为 xx,将 PcP_c 改为 yy。然后,解决以下问题并打印答案。

NN 个工作,编号从 11NN。 从今天开始(考虑为第 11 天),你将选择并完成一个工作,持续 NN 天。 如果你在第 DiD_i 天或之前完成工作 ii,你将获得 PiP_i 的奖励。(如果你在第 DiD_i 天之前没有完成,你将一无所获。) 通过选择完成工作的最优顺序,找到你可以实现的最大总奖励。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given two sequences of length NN: D=(D1,D2,,DN)D=(D_1, D_2, \dots, D_N) and P=(P1,P2,,PN)P=(P_1, P_2, \dots, P_N).

Process QQ queries in the order they are given. Each query is given in the following format:

  • c x y: Change DcD_c to xx and PcP_c to yy. Then, solve the following problem and print the answer.

There are NN jobs numbered 11 to NN.
Starting from today (consider this as day 11), you will choose and complete one job per day for NN days.
If you complete job ii on or before day DiD_i, you will receive a reward of PiP_i. (If you do not complete it by day DiD_i, you get nothing.)
Find the maximum total reward you can achieve by choosing the optimal order of completing the jobs.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Q1051 \leq Q \leq 10^5
  • 1DiN1 \leq D_i \leq N
  • 1Pi1091 \leq P_i \leq 10^9
  • 1cN1 \leq c \leq N
  • 1xN1 \leq x \leq N
  • 1y1091 \leq y \leq 10^9
  • All input values are integers.

Input

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

NN QQ

D1D_1 D2D_2 \dots DND_N

P1P_1 P2P_2 \dots PNP_N

query1\mathrm{query}_1

query2\mathrm{query}_2

\vdots

queryQ\mathrm{query}_Q

Each query is given in the following format.

cc xx yy

Output

Print QQ lines. The ii-th line should contain the answer to the ii-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 D3D_3 to 11 and P3P_3 to 44. Now, D=(1,2,1)D = (1, 2, 1) and P=(3,6,4)P = (3, 6, 4).
  • In the subproblem, one optimal procedure is to complete job 33 on day 11, job 22 on day 22, and job 11 on day 33. The total reward is 1010, so print 1010.

The second query is as follows:

  • Update D2D_2 to 33 and P2P_2 to 99. Now, D=(1,3,1)D = (1, 3, 1) and P=(3,9,4)P = (3, 9, 4).
  • In the subproblem, one optimal procedure is to complete job 33 on day 11, job 11 on day 22, and job 22 on day 33. The total reward is 1313, so print 1313.

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