Heavy rain (Easy)
Time limit2sMemory limit1024 MB
Given N walls with heights, print the total rain that can be trapped after each of Q updates that raise one wall's height.
- Level
Medium6 of 10
- Topics
- Array, Segment tree
- Solved
- No attempts yet
Problem
Rain falls endlessly on cells in a row. Initially, cell has a wall of height . When the water trapped inside a wall fills up, it overflows past the left and right ends and disappears. Rain does not move in any direction other than left and right along the row.
There are queries. Each query consists of and , meaning that from then on, the wall in cell has height . It is guaranteed that .
After each query, print the maximum amount of rain that can end up collecting.
Input
The first line contains and in that order (; ).
The second line contains the initial heights in order ().
Each of the next lines contains two integers and , separated by a space (; ).
All numbers in the input are integers.
Output
Print lines. The -th line is the answer after the -th query.