ALGO ARTIS プログラミングコンテスト2023 秋 (AtCoder Regular Contest 168)
F
Up-Down Queries
AtCoder
未评级
原题
← E→
翻译中…

Problem Statement

翻译中…

For an integer sequence $x=(x_1,x_2,\cdots,x_N)$ of length $N$ with each element being between $0$ and $M$, inclusive, we define $f(x)$ as follows:

翻译中…
  • Prepare an integer sequence $y=(y_1,y_2,\cdots,y_M)$ of length $M$. Initially, set all elements of $y$ to $0$. Then, for each $i=1,2,\cdots,N$, in order, perform the following operations:
  • For each integer $j$ ($1 \leq j \leq x_i$), replace the value of $y_j$ with $\max(y_j-1,0)$.
    • For each integer $j$ ($x_i < j \leq M$), replace the value of $y_j$ with $y_j+1$.
  • The sum of the elements of $y$ after all operations is the value of $f(x)$.
翻译中…

You are given an integer sequence $A=(A_1,A_2,\cdots,A_N)$ of length $N$ with each element being between $0$ and $M$, inclusive. Process $Q$ queries:

翻译中…
  • The $i$-th query: Given integers $X_i$ and $Y_i$, replace the value of $A_{X_i}$ with $Y_i$. Then, print the value of $f(A)$.
翻译中…

Constraints

翻译中…
  • $1 \leq N,M,Q \leq 250000$
  • $0 \leq A_i \leq M$
  • $1 \leq X_i \leq N$
  • $0 \leq Y_i \leq M$
  • All input values are integers.
翻译中…

Input

翻译中…

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

翻译中…

N M Q
A_1 A_2 \cdots A_N
X_1 Y_1
X_2 Y_2
\vdots
X_Q Y_Q

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3 4 2
1 2 3
1 4
3 0
Output #1
2
6
Consider the first query. We replace the value of $A_1$ with $4$, making $A=(4,2,3)$. Then, the value of $f(A)$ is calculated as follows: - Prepare $y=(0,0,0,0)$. - Perform the operation for $A_1=4$, resulting in $y=(0,0,0,0)$. - Perform the operation for $A_2=2$, resulting in $y=(0,0,1,1)$. - Perform the operation for $A_3=3$, resulting in $y=(0,0,0,2)$. - The sum of the elements of $y$, which equals $2$, is the value of $f(A)$. Next, consider the second query. We replace the value of $A_3$ with $0$, making $A=(4,2,0)$. Then, the value of $f(A)$ is calculated as follows: - Prepare $y=(0,0,0,0)$. - Perform the operation for $A_1=4$, resulting in $y=(0,0,0,0)$. - Perform the operation for $A_2=2$, resulting in $y=(0,0,1,1)$. - Perform the operation for $A_3=0$, resulting in $y=(1,1,2,2)$. - The sum of the elements of $y$, which equals $6$, is the value of $f(A)$.
Input #2
7 2 9
2 0 2 2 0 1 0
1 1
3 0
4 0
4 1
6 1
3 2
2 0
3 2
2 0
Output #2
4
7
11
9
9
6
6
6
6
Input #3
20 200000 10
39664 143179 193565 153887 16141 91985 51452 155409 116777 190060 87620 64458 106481 51272 9108 100995 139248 18243 181424 6182
4 196305
13 59753
8 96194
6 57037
19 125781
16 142779
15 13967
10 17772
16 84763
12 17283
Output #3
1145670
1234421
1352851
1352851
1464137
1380569
1380569
1608611
1724643
1736769
题目信息
题号
arc168_f
时间限制
5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。