#P12438. [NERC2023] Great City Saint Petersburg
[NERC2023] Great City Saint Petersburg
题目描述
Saint Petersburg is the most beautiful city in the world unless it is raining. For the sake of this problem, we will assume it is raining every single day.
One of the streets in Saint Petersburg has an unusual shape --- it is a narrow stripe of sections meter long each, where section is at the height meters from the ground. The stripe is meter deep and bounded on the front and on the back by incredibly high buildings. Because of this, when it is raining, a certain amount of rain will accumulate, unable to flow out of the street from either its leftmost or rightmost end. Given the heights , you need to determine the amount of rain (in cubic meters) which will accumulate on the street.
Moreover, your colleagues from the metropolitan construction company will be visiting for days and on day they will be laying asphalt on all sections from to inclusive, thus increasing the height of each section by meter. You need to determine the total amount of water which accumulates on the street before the construction works, and also after every single day of the construction works.
输入格式
The first line contains the number of blocks and the number of construction events (). The second line contains integers () --- the height of each section before all the events. Each of the following lines contains a pair of integers , (), denoting the construction work from to inclusive.
输出格式
Print integers --- the amount of water on the street before all updates, and also after every update.
5 4
3 2 1 2 3
1 5
2 4
1 2
5 5
4
4
1
1
3
7 3
1 1000000000 1 1 1 1000000000 1
1 3
4 5
5 7
2999999997
2999999996
2999999994
2999999996
提示
The picture illustrates the amount of water accumulating on the street in the first example.