#P8767. [蓝桥杯 2021 国 A] 冰山

[蓝桥杯 2021 国 A] 冰山

Problem Description

In a sea area, there are some icebergs. The volume of the ii-th iceberg is ViV_{i}.

As the temperature changes, the volume of the icebergs may increase or decrease. On day ii, the change amount for every iceberg is XiX_{i}. When Xi>0X_{i} > 0, the volume of all icebergs increases by XiX_{i}; when Xi<0X_{i} < 0, the volume of all icebergs decreases by Xi-X_{i}; when Xi=0X_{i} = 0, the volume of all icebergs does not change.

If, after the change on day ii, the volume of an iceberg becomes less than or equal to 00, then the iceberg disappears forever.

There is a size limit kk for icebergs. If, after the change on day ii, the volume VjV_{j} of an iceberg jj is greater than kk, then it will split into one iceberg of volume kk and VjkV_{j} - k icebergs of volume 11.

Before the end of day ii (after the growth, shrinkage, disappearance, and splitting are all completed), one iceberg of volume YiY_{i} will drift in (Yi=0Y_{i} = 0 means no iceberg drifts in).

Xiaolan observed this sea area for mm consecutive days and accurately recorded the changes of the icebergs. Xiaolan wants to know the total sum of volumes of all icebergs at the end of each day (including the newly drifted-in one).

Since the answer may be very large, please output the remainder when it is divided by 998244353998244353.

Input Format

The first line contains three integers n,m,kn, m, k, representing the initial number of icebergs, the number of observed days, and the size limit of an iceberg.

The second line contains nn integers V1,V2,,VnV_{1}, V_{2}, \cdots, V_{n}, representing the initial volume of each iceberg.

The next mm lines describe the iceberg changes for the mm observed days. The ii-th line contains two integers Xi,YiX_{i}, Y_{i}, with meanings as described above.

Output Format

Output mm lines. Each line contains one integer, which is the remainder of the total sum of volumes of all icebergs at the end of that day divided by 998244353998244353.

1 3 6
1
6 1
2 2
-1 1
8
16
11

Hint

Sample Explanation

In this sample explanation, [a1,a2,,an]\left[a_{1}, a_{2}, \cdots, a_{n}\right] is used to represent the volume of each iceberg.

Initially, the icebergs are [1][1].

At the end of day 11, there are 33 icebergs: [1,1,6][1,1,6].

At the end of day 22, there are 66 icebergs: [1,1,2,3,3,6][1,1,2,3,3,6].

At the end of day 33, there are 55 icebergs: [1,1,2,2,5][1,1,2,2,5].

Constraints and Conventions for Test Cases

For 40%40\% of the test cases, n,m,k2000n, m, k \leq 2000.

For 60%60\% of the test cases, n,m,k20000n, m, k \leq 20000.

For all test cases, 1n,m1051 \leq n, m \leq 10^5, 1k1091 \leq k \leq 10^{9}, 1Vik1 \leq V_{i} \leq k, 0Yik0 \leq Y_{i} \leq k, kXik-k \leq X_{i} \leq k.

Lanqiao Cup 2021 National Contest Group A, Problem G.

Translated by ChatGPT 5