Problem I
Castle Wall
Languages
en
sv
The owner of the castle Drakfjälls Kastell is worried about
a potential siege. If this happens, he wants the wall to be
sturdy, so he plans to reinforce it. The castle wall consists
of
![\includegraphics[scale=0.3]{mur1.png}](/problems/slottsmur/file/statement/en/img-0001.png)
The castle owner is also concerned about moisture damage when it rains, which could potentially worsen if he reinforces the wall. When it rains, all the wall’s gaps will fill up with water, as long as the water cannot drain off at the sides. If it had rained on the previous example wall, water would have collected at the blue squares.
![\includegraphics[scale=0.3]{mur2.png}](/problems/slottsmur/file/statement/en/img-0002.png)
To be strategic with his reconstruction, he wants to know how certain reinforcements would affect the amount of rainwater that collects in the wall if parts of it were destroyed in a siege. At his disposal, he has you, the castle’s theoretical computer scientist. The castle owner will ask you two types of queries:
-
Given two values
and . If all wall segments are destroyed except those in the interval , how much rainwater would collect in the wall if it starts raining? Note that the wall isn’t actually destroyed, so this doesn’t affect future queries. -
Given two values
and , increase the height of the th wall segment by . This is a permanent change that will affect future queries.
Input
The first line of input contains the integers
Then follow
The following
-
If
, it’s followed by ( ). You should then output the answer to a type query as described above. -
If
, it’s followed by ( , ). You should then increase the height of the th wall segment by . It’s guaranteed that the height of the wall segment remains less than or equal to after this.
Output
For each type
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.
Group |
Points |
Constraints |
|
|
|
|
|
All queries are of type |
|
|
|
|
|
|
|
|
No additional constraints. |
Explanation of Sample 1
In the first query, we’re asked to calculate the amount of
water that collects if we destroy everything outside
![\includegraphics[scale=0.2]{mur2.png}](/problems/slottsmur/file/statement/en/img-0002.png)
In the second query, the Castle owner wants to know what happens if part of the right end of the wall is destroyed. The wall segments that would be destroyed are marked in dark gray.
![\includegraphics[scale=0.2]{mur3.png}](/problems/slottsmur/file/statement/en/img-0003.png)
In the third query, part of the wall is raised. This affects the fourth query, which looks like the following.
![\includegraphics[scale=0.2]{mur4.png}](/problems/slottsmur/file/statement/en/img-0004.png)
Sample Input 1 | Sample Output 1 |
---|---|
6 4 2 1 4 1 1 3 1 1 6 1 1 4 2 6 1 1 1 6 |
5 1 7 |
Sample Input 2 | Sample Output 2 |
---|---|
6 4 3 2 1 3 2 4 1 1 6 2 3 3 1 2 6 1 1 4 |
4 3 1 |
Footnotes
- See https://en.wikipedia.org/wiki/Discrete_uniform_distribution