#P8767. [蓝桥杯 2021 国 A] 冰山
[蓝桥杯 2021 国 A] 冰山
Problem Description
In a sea area, there are some icebergs. The volume of the -th iceberg is .
As the temperature changes, the volume of the icebergs may increase or decrease. On day , the change amount for every iceberg is . When , the volume of all icebergs increases by ; when , the volume of all icebergs decreases by ; when , the volume of all icebergs does not change.
If, after the change on day , the volume of an iceberg becomes less than or equal to , then the iceberg disappears forever.
There is a size limit for icebergs. If, after the change on day , the volume of an iceberg is greater than , then it will split into one iceberg of volume and icebergs of volume .
Before the end of day (after the growth, shrinkage, disappearance, and splitting are all completed), one iceberg of volume will drift in ( means no iceberg drifts in).
Xiaolan observed this sea area for 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 .
Input Format
The first line contains three integers , representing the initial number of icebergs, the number of observed days, and the size limit of an iceberg.
The second line contains integers , representing the initial volume of each iceberg.
The next lines describe the iceberg changes for the observed days. The -th line contains two integers , with meanings as described above.
Output Format
Output 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 .
1 3 6
1
6 1
2 2
-1 1
8
16
11
Hint
Sample Explanation
In this sample explanation, is used to represent the volume of each iceberg.
Initially, the icebergs are .
At the end of day , there are icebergs: .
At the end of day , there are icebergs: .
At the end of day , there are icebergs: .
Constraints and Conventions for Test Cases
For of the test cases, .
For of the test cases, .
For all test cases, , , , , .
Lanqiao Cup 2021 National Contest Group A, Problem G.
Translated by ChatGPT 5