#abc306e. E - Best Performances

E - Best Performances

Score : 475475 points

问题描述

我们有一个长度为 NN 的序列 A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N)。最初,所有项均为 00

给定一个整数 KK,我们定义一个函数 f(A)f(A) 如下:

  • 首先,将序列 AA 按降序排序得到序列 BB(使其单调非增)。
  • 然后,令 f(A)=B1+B2++BKf(A)=B_1 + B_2 + \dots + B_K

我们考虑对这个序列应用 QQ 次更新操作。按照顺序对序列 AA 应用以下操作,对于 i=1,2,,Qi=1,2,\dots,Q,并在每次更新后输出此时的 f(A)f(A) 值。

  • AXiA_{X_i} 改为 YiY_i

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a sequence A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N) of length NN. Initially, all the terms are 00.
Using an integer KK given in the input, we define a function f(A)f(A) as follows:

  • Let BB be the sequence obtained by sorting AA in descending order (so that it becomes monotonically non-increasing).
  • Then, let f(A)=B1+B2++BKf(A)=B_1 + B_2 + \dots + B_K.

We consider applying QQ updates on this sequence.
Apply the following operation on the sequence AA for i=1,2,,Qi=1,2,\dots,Q in this order, and print the value f(A)f(A) at that point after each update.

  • Change AXiA_{X_i} to YiY_i.

Constraints

  • All input values are integers.
  • 1KN5×1051 \le K \le N \le 5 \times 10^5
  • 1Q5×1051 \le Q \le 5 \times 10^5
  • 1XiN1 \le X_i \le N
  • 0Yi1090 \le Y_i \le 10^9

Input

The input is given from Standard Input in the following format:

NN KK QQ

X1X_1 Y1Y_1

X2X_2 Y2Y_2

\vdots

XQX_Q YQY_Q

Output

Print QQ lines in total. The ii-th line should contain the value f(A)f(A) as an integer when the ii-th update has ended.

Sample Input 1

4 2 10
1 5
2 1
3 3
4 2
2 10
1 0
4 0
3 1
2 0
3 0

Sample Output 1

5
6
8
8
15
13
13
11
1
0

In this input, N=4N=4 and K=2K=2. Q=10Q=10 updates are applied.

  • The 11-st update makes A=(5,0,0,0)A=(5, 0,0,0). Now, f(A)=5f(A)=5.
  • The 22-nd update makes A=(5,1,0,0)A=(5, 1,0,0). Now, f(A)=6f(A)=6.
  • The 33-rd update makes A=(5,1,3,0)A=(5, 1,3,0). Now, f(A)=8f(A)=8.
  • The 44-th update makes A=(5,1,3,2)A=(5, 1,3,2). Now, f(A)=8f(A)=8.
  • The 55-th update makes A=(5,10,3,2)A=(5,10,3,2). Now, f(A)=15f(A)=15.
  • The 66-th update makes A=(0,10,3,2)A=(0,10,3,2). Now, f(A)=13f(A)=13.
  • The 77-th update makes A=(0,10,3,0)A=(0,10,3,0). Now, f(A)=13f(A)=13.
  • The 88-th update makes A=(0,10,1,0)A=(0,10,1,0). Now, f(A)=11f(A)=11.
  • The 99-th update makes A=(0,0,1,0)A=(0, 0,1,0). Now, f(A)=1f(A)=1.
  • The 1010-th update makes A=(0,0,0,0)A=(0, 0,0,0). Now, f(A)=0f(A)=0.

update @ 2024/3/10 08:39:16