CF1477E.Nezzar and Tournaments

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:512MB

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 nn players, and the second team consists of mm players. Each player has a potential: the potential of the ii-th player in the first team is aia_i, and the potential of the ii-th player in the second team is bib_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 kk, 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 xx, and the potential of the previous player be yy (yy equals xx for the first player). Then, x−yx-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 00. 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 scorefscore_f and the score of the second team be scoresscore_s. Nezzar wants to find the maximum value of scoref−scoresscore_f - score_s over all possible orders of players on the stage.

However, situation often changes and there are qq events that will happen. There are three types of events:

  • 11 pospos xx — change aposa_{pos} to xx;
  • 22 pospos xx — change bposb_{pos} to xx;
  • 33 xx — tournament is held with k=xk = x and Nezzar wants you to compute the maximum value of scoref−scoresscore_f - score_s.

Can you help Nezzar to answer the queries of the third type?

在著名的“Oh-Suit-United”锦标赛中,两支队伍正为珍贵的“胡椒点数”(pepper points)这一大奖展开对决。

第一支队伍由 nn 名选手组成,第二支队伍由 mm 名选手组成。每名选手均有一个“潜力值”:第一支队伍中第 ii 名选手的潜力值为 aia_i,第二支队伍中第 ii 名选手的潜力值为 bib_i。

在锦标赛中,所有选手将以某种顺序依次登上舞台。现场设有一台计分装置,其初始值为整数 kk,用于评估所有选手的表现。

所有选手的得分将按其登台顺序依次计算。设当前选手的潜力值为 xx,前一位选手的潜力值为 yy(对于第一位选手,规定 y=xy = x)。则将 x−yx - y 加到计分装置当前值上;随后,若计分装置的值变为负数,则立即将其重置为 00;最后,该选手的得分即为计分装置此时的值。一支队伍的总分等于其所有队员得分之和。

作为第一支队伍的狂热粉丝,Nezzar 极度渴望第一支队伍取得最大胜利。他现在想知道:第一支队伍与第二支队伍总分之差的最大可能值是多少?

形式化地,记第一支队伍的总分为 scorefscore_f,第二支队伍的总分为 scoresscore_s。Nezzar 希望求出在所有可能的选手登台顺序下,scoref−scoresscore_f - score_s 的最大值。

然而,局势常常变化,共会发生 qq 个事件。事件共分三种类型:

  • 11 pospos xx —— 将 aposa_{pos} 修改为 xx;
  • 22 pospos xx —— 将 bposb_{pos} 修改为 xx;
  • 33 xx —— 举办锦标赛,此时计分装置初始值 k=xk = x,Nezzar 要求你计算 scoref−scoresscore_f - score_s 的最大可能值。

你能帮助 Nezzar 回答所有第 3 类查询吗?

输入格式

The first line contains three integers nn, mm, and qq (1≤n,m≤2⋅105,1≤q≤5⋅1051 \le n,m \le 2 \cdot 10^5, 1 \le q \le 5 \cdot 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1060 \le a_i \le 10^6).

The third line contains mm integers b1,b2,…,bmb_1, b_2, \ldots, b_m (0≤bi≤1060 \le b_i \le 10^6).

The following qq lines contain descriptions of events, described in the statement, each in one of the three possible formats:

  • 11 pospos xx (1≤pos≤n1 \le pos \le n, 0≤x≤1060 \le x \le 10^6);
  • 22 pospos xx (1≤pos≤m1 \le pos \le m, 0≤x≤1060 \le x \le 10^6);
  • 33 xx (0≤x≤1060 \le x \le 10^6).

第一行包含三个整数 nn、mm 和 qq(1≤n,m≤2⋅1051 \le n,m \le 2 \cdot 10^5,1≤q≤5⋅1051 \le q \le 5 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1060 \le a_i \le 10^6)。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \ldots, b_m(0≤bi≤1060 \le b_i \le 10^6)。

接下来的 qq 行描述了题目陈述中所述的事件,每行均为以下三种格式之一:

  • 11 pospos xx(1≤pos≤n1 \le pos \le n,0≤x≤1060 \le x \le 10^6);
  • 22 pospos xx(1≤pos≤m1 \le pos \le m,0≤x≤1060 \le x \le 10^6);
  • 33 xx(0≤x≤1060 \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=5k = 5. It would be optimal to arrange players in such way (here their potentials are written):

7‾\underline{7}, 33, 55, 44, 66, 1‾\underline{1}, 2‾\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\max(5 + (7 - 7), 0) = 5 for the 1‾\underline{1}-st player;
  • max⁡(5+(3−7),0)=1\max(5 + (3 - 7), 0) = 1 for the 22-nd player;
  • max⁡(1+(5−3),0)=3\max(1 + (5 - 3), 0) = 3 for the 33-rd player;
  • max⁡(3+(4−5),0)=2\max(3 + (4 - 5), 0) = 2 for the 44-th player;
  • max⁡(2+(6−4),0)=4\max(2 + (6 - 4), 0) = 4 for the 55-th player;
  • max⁡(4+(1−6),0)=0\max(4 + (1 - 6), 0) = 0 for the 6‾\underline{6}-th player;
  • max⁡(0+(2−1),0)=1\max(0 + (2 - 1), 0) = 1 for the 7‾\underline{7}-th player.

So, scoref=5+0+1=6score_f = 5 + 0 + 1 = 6 and scores=1+3+2+4=10score_s = 1 + 3 + 2 + 4 = 10. The score difference is 6−10=−46 - 10 = -4. It can be proven, that it is the maximum possible score difference.

在第一个测试用例的第一个查询中,锦标赛的参数为 k=5k = 5。此时,将选手按如下方式排列(括号内为其潜力值)是最优的:

7‾\underline{7}, 33, 55, 44, 66, 1‾\underline{1}, 2‾\underline{2}(带下划线的数字表示第一支队伍选手的潜力值)。

按出场顺序编号的各位选手的个人得分如下:

  • 第 1‾\underline{1} 位选手:max⁡(5+(7−7),0)=5\max(5 + (7 - 7), 0) = 5;
  • 第 22 位选手:max⁡(5+(3−7),0)=1\max(5 + (3 - 7), 0) = 1;
  • 第 33 位选手:max⁡(1+(5−3),0)=3\max(1 + (5 - 3), 0) = 3;
  • 第 44 位选手:max⁡(3+(4−5),0)=2\max(3 + (4 - 5), 0) = 2;
  • 第 55 位选手:max⁡(2+(6−4),0)=4\max(2 + (6 - 4), 0) = 4;
  • 第 6‾\underline{6} 位选手:max⁡(4+(1−6),0)=0\max(4 + (1 - 6), 0) = 0;
  • 第 7‾\underline{7} 位选手:max⁡(0+(2−1),0)=1\max(0 + (2 - 1), 0) = 1。

因此,scoref=5+0+1=6score_f = 5 + 0 + 1 = 6,scores=1+3+2+4=10score_s = 1 + 3 + 2 + 4 = 10。分差为 6−10=−46 - 10 = -4。可以证明,这是可能达到的最大分差。

输入解题思路,AI测评打分。不知道怎么写?

首页