CF1477E.Nezzar and Tournaments
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai , and the potential of the i -th player in the second team is bi .
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 scoref and the score of the second team be scores . Nezzar wants to find the maximum value of scoref−scores 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 apos to x ;
- 2 pos x — change bpos to x ;
- 3 x — tournament is held with k=x and Nezzar wants you to compute the maximum value of scoref−scores .
Can you help Nezzar to answer the queries of the third type?
输入格式
The first line contains three integers n , m , and q ( 1≤n,m≤2⋅105,1≤q≤5⋅105 ).
The second line contains n integers a1,a2,…,an ( 0≤ai≤106 ).
The third line contains m integers b1,b2,…,bm ( 0≤bi≤106 ).
The following q lines contain descriptions of events, described in the statement, each in one of the three possible formats:
- 1 pos x ( 1≤pos≤n , 0≤x≤106 );
- 2 pos x ( 1≤pos≤m , 0≤x≤106 );
- 3 x ( 0≤x≤106 ).
输出格式
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):
7 , 3 , 5 , 4 , 6 , 1 , 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 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 6 -th player;
- max(0+(2−1),0)=1 for the 7 -th player.
So, scoref=5+0+1=6 and scores=1+3+2+4=10 . The score difference is 6−10=−4 . It can be proven, that it is the maximum possible score difference.