#P16702. [MCO 2026] 雨水收集
[MCO 2026] 雨水收集
Problem Description
In the town of MCO, there are towers standing side by side. From left to right, the initial height of the -th tower (indexed from ) is . After a heavy rain, water may accumulate on top of the towers. Evirir, a resident of MCO, wants to know how much rainwater these towers can collect in total.
For an interval of towers (i.e., towers ), its rainfall amount is defined as follows:
- For each tower , if and only if there exist towers and such that , and both tower and tower are at least higher than tower , i.e.,$$H_i - H_j \ge x \quad \text{and} \quad H_k - H_j \ge x,$$then a column of water of height can be stored on tower .
- Let be the maximum possible height of the water column that can be stored on tower .
- The rainfall amount is defined as i.e., the sum of the maximum water column heights that can be stored on these towers.
Evirir is confident in the new generation of Malaysian OI contestants, so if you were only asked to compute the rainfall amount for one interval, that would be too easy. Instead, you need to process operations, and each operation is one of the following two types:
- Update: --- add to for all .
- Query: --- output the rainfall amount of the tower interval .
Notes:
- When answering a query for interval , when computing and the rainfall amount, you must not consider towers outside this interval. Towers outside the interval cannot be used to hold water.
- Tower heights can be negative, but the rules remain the same. See the sample for related explanation.
Input Format
The first line contains two integers and separated by spaces.
The second line contains integers separated by spaces.
The next lines each describe one operation, containing several integers separated by spaces:
- Update: --- add to for all .
- Query: --- output the rainfall amount of the tower interval .
Output Format
For each query, output the rainfall amount of the towers in interval in order, one answer per line.
9 7
5 3 1 3 -1 1 2 5 3
1 1 6
1 0 8
0 1 4 2
0 6 8 -4
1 1 6
1 3 6
1 6 6
6
21
2
0
0
5 6
-2 3 1 4 2
0 0 2 1
0 0 4 3
0 3 4 8
0 0 0 10
0 1 3 1
1 0 4
10
Hint
Hint
This sample applies to subtasks 1, 5, and 6.
There are towers. Below is a visualization of the updates and queries:
:::align{center}
:::
In the first query , we consider towers to . Look at tower with height . Tower can store a water column of height , because:
- Tower has height , which is higher than tower .
- Tower has height , which is higher than tower . But tower cannot store a water column of height , because there is no tower satisfying whose height is at least higher than tower (i.e., height at least ). Note that you cannot take , because is not within the queried interval . Therefore, , represented by the unit of water on tower .
In the second query , we consider towers to . Look at tower with height . Tower can store a water column of height , because the heights of tower and tower are both , both higher than tower . It can also be proven that is already the maximum possible height, so .
In the update , the heights of towers to are all increased by . In the update , the heights of towers to are all decreased by .
In the query , note that even if a tower has a negative height, it still needs taller surrounding towers to store water.
Note that by taking , it is always possible to store at least a water column of height on a tower.
This sample applies to subtasks 1, 5, and 6.
Scoring
For all test cases, the input satisfies the following Constraints:
- For all ,
- For all updates and queries,
- For all updates,
- There is at least one query operation.
| Subtask | Points | Additional Constraints |
|---|---|---|
| and there are no update operations in the input | ||
| In updates, and , and in queries, | ||
| --- |
Translated by ChatGPT 5