#P13963. [ICPC 2023 Nanjing R] 接雨水
[ICPC 2023 Nanjing R] 接雨水
Description
There is a histogram represented by an integer sequence of length . For the -th bar from left to right, its height is and its width is .
We'll perform modifications to the histogram. The -th modification can be represented by a pair of integers indicating that we'll increase the height of the -th bar by .
After each modification, answer the following query: Calculate how much water this histogram can trap if a heavy rain pours onto it and fills all the pits as much as possible.
More formally, given an integer sequence of length , the -th modification will increase by . After each modification, answer the following query: Let and , calculate
$$\sum\limits_{i = 1}^n \left( \min(f_i, g_i) - a_i \right)$$Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains an integer () indicating the number of bars in the histogram.
The second line contains integers () where indicates the initial height of the -th bar.
The third line contains an integer () indicating the number of modifications.
For the following lines, the -th line contains two integers and (, ) indicating that the -th modification increases the height of the -th bar by .
It is guaranteed that neither the sum of nor the sum of of all test cases will exceed .
Output Format
For each modification output one line containing one integer indicating how much rain water this histogram can trap.
2
6
1 2 3 4 5 6
2
1 2
3 3
5
100 10 1 10 100
1
3 100
1
4
180
京公网安备 11011102002149号