308176: CF1477E. Nezzar and Tournaments

Memory Limit:512 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Nezzar and Tournaments

题意翻译

给你长为 $n,m$ 的两个数列 $a,b$,初始有个值为 $k$ 的计分板。 设 $c$ 为一个长为 $n+m$ 的数列,$c$ 中每个数**恰对应 $a,b$ 中的某个数**,令 $d_i$ 为第 $i$ 个数原本属于哪个数列。 依次往计分板中加入数 $c_i$,计分板增加 $c_i-c_{i-1}$ 的权值(可负),**初始有 $c_0:=c_1$ 避开边界情况**。 **计分板始终对 $0$ 取 $\max$,设第 $i$ 个数加入后计分板为 $v_i$,形式化的有 $v_i=\max{(0,v_{i-1}+c_i-c_{i-1})}$。**(注:如上文所述有 $v_1=k$ 在加入 $c_i$ 这个数时,会对 $d_i$ 这个数列产生 $v_i$ 的贡献,设最终的贡献分别为 $W_a,W_b$。 求 $c$ 的所有情况中 $W_a-W_b$ 的最大值。 支持操作:单点修改 $a,b$,给定 $k$ 进行询问。 $1\le n,m\le2\times 10^5,1\le q\le 5\times 10^5,1\le a_i,b_i\le 10^6$,其中 $q$ 为操作次数。

题目描述

In the famous Oh-Suit-United tournament, two teams are playing against each other for the grand prize of precious pepper points. The first team consists of $ n $ players, and the second team consists of $ m $ players. Each player has a potential: the potential of the $ i $ -th player in the first team is $ a_i $ , and the potential of the $ i $ -th player in the second team is $ b_i $ . In the tournament, all players will be on the stage in some order. There will be a scoring device, initially assigned to an integer $ k $ , which will be used to value the performance of all players. The scores for all players will be assigned in the order they appear on the stage. Let the potential of the current player be $ x $ , and the potential of the previous player be $ y $ ( $ y $ equals $ x $ for the first player). Then, $ x-y $ is added to the value in the scoring device, Afterwards, if the value in the scoring device becomes negative, the value will be reset to $ 0 $ . Lastly, the player's score is assigned to the current value on the scoring device. The score of a team is the sum of the scores of all its members. As an insane fan of the first team, Nezzar desperately wants the biggest win for the first team. He now wonders what is the maximum difference between scores of the first team and the second team. Formally, let the score of the first team be $ score_f $ and the score of the second team be $ score_s $ . Nezzar wants to find the maximum value of $ score_f - score_s $ over all possible orders of players on the stage. However, situation often changes and there are $ q $ events that will happen. There are three types of events: - $ 1 $ $ pos $ $ x $ — change $ a_{pos} $ to $ x $ ; - $ 2 $ $ pos $ $ x $ — change $ b_{pos} $ to $ x $ ; - $ 3 $ $ x $ — tournament is held with $ k = x $ and Nezzar wants you to compute the maximum value of $ score_f - score_s $ . Can you help Nezzar to answer the queries of the third type?

输入输出格式

输入格式


The first line contains three integers $ n $ , $ m $ , and $ q $ ( $ 1 \le n,m \le 2 \cdot 10^5, 1 \le q \le 5 \cdot 10^5 $ ). The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \le a_i \le 10^6 $ ). The third line contains $ m $ integers $ b_1, b_2, \ldots, b_m $ ( $ 0 \le b_i \le 10^6 $ ). The following $ q $ lines contain descriptions of events, described in the statement, each in one of the three possible formats: - $ 1 $ $ pos $ $ x $ ( $ 1 \le pos \le n $ , $ 0 \le x \le 10^6 $ ); - $ 2 $ $ pos $ $ x $ ( $ 1 \le pos \le m $ , $ 0 \le x \le 10^6 $ ); - $ 3 $ $ x $ ( $ 0 \le x \le 10^6 $ ).

输出格式


For each query of the third type print the answer to this query.

输入输出样例

输入样例 #1

3 4 3
1 2 7
3 4 5 6
3 5
1 1 10
3 5

输出样例 #1

-4
9

输入样例 #2

7 8 12
958125 14018 215153 35195 90380 30535 204125
591020 930598 252577 333333 999942 1236 9456 82390
3 123458
2 4 444444
3 123456
1 2 355555
3 123478
3 1111
2 6 340324
3 1111
2 8 999999
2 7 595959
3 222222
3 100

输出样例 #2

1361307
1361311
1702804
1879305
1821765
1078115
1675180

说明

In the first query of the first test, the tournament is held with $ k = 5 $ . It would be optimal to arrange players in such way (here their potentials are written): $ \underline{7} $ , $ 3 $ , $ 5 $ , $ 4 $ , $ 6 $ , $ \underline{1} $ , $ \underline{2} $ (underlined numbers are potentials of players that are from the first team). The individual scores of players, numbered in the order of their appearance, are: - $ \max(5 + (7 - 7), 0) = 5 $ for the $ \underline{1} $ -st player; - $ \max(5 + (3 - 7), 0) = 1 $ for the $ 2 $ -nd player; - $ \max(1 + (5 - 3), 0) = 3 $ for the $ 3 $ -rd player; - $ \max(3 + (4 - 5), 0) = 2 $ for the $ 4 $ -th player; - $ \max(2 + (6 - 4), 0) = 4 $ for the $ 5 $ -th player; - $ \max(4 + (1 - 6), 0) = 0 $ for the $ \underline{6} $ -th player; - $ \max(0 + (2 - 1), 0) = 1 $ for the $ \underline{7} $ -th player. So, $ score_f = 5 + 0 + 1 = 6 $ and $ score_s = 1 + 3 + 2 + 4 = 10 $ . The score difference is $ 6 - 10 = -4 $ . It can be proven, that it is the maximum possible score difference.

Input

题意翻译

给你长为 $n,m$ 的两个数列 $a,b$,初始有个值为 $k$ 的计分板。 设 $c$ 为一个长为 $n+m$ 的数列,$c$ 中每个数**恰对应 $a,b$ 中的某个数**,令 $d_i$ 为第 $i$ 个数原本属于哪个数列。 依次往计分板中加入数 $c_i$,计分板增加 $c_i-c_{i-1}$ 的权值(可负),**初始有 $c_0:=c_1$ 避开边界情况**。 **计分板始终对 $0$ 取 $\max$,设第 $i$ 个数加入后计分板为 $v_i$,形式化的有 $v_i=\max{(0,v_{i-1}+c_i-c_{i-1})}$。**(注:如上文所述有 $v_1=k$ 在加入 $c_i$ 这个数时,会对 $d_i$ 这个数列产生 $v_i$ 的贡献,设最终的贡献分别为 $W_a,W_b$。 求 $c$ 的所有情况中 $W_a-W_b$ 的最大值。 支持操作:单点修改 $a,b$,给定 $k$ 进行询问。 $1\le n,m\le2\times 10^5,1\le q\le 5\times 10^5,1\le a_i,b_i\le 10^6$,其中 $q$ 为操作次数。

加入题单

算法标签: