L. All’s Wall That Ends Wall
题目描述
In the magical forest, you come upon N walls that you think is a great place to store water for your animal friends. The ith wall consists of ai blocks stacked on top of each other.
Your job is to answer queries of two types:
For queries of the first type, print the amount of water that could be stored between all the walls.
For queries of the second type, increase the number of blocks on the xth wall by v.
输入
The first line of input is T – the number of test cases.
The first line of each test case is integers N and Q (1 ≤ N, Q ≤ 105).
The second line contains N space-separated integers ai (1 ≤ ai ≤ 105).
The next Q lines contain either ‘P’ – denoting a query of the first type, or ‘U’ followed by x and v – denoting a query of the second type (1 ≤ x ≤ N) (1 ≤ v ≤ 104).
输出
For each test case and query of the first type, output on a line the amount of water that could be stored between the walls.
样例
inputCopy
1
6 3
2 1 4 2 1 3
P
U 1 2
P
outputCopy
4
6
题意
线段树维护即可

本文介绍了一种使用线段树解决特定水域计算的问题,具体为:在一排由不同高度的墙组成的区域中,计算可以存储的水量,并支持对任意一堵墙的高度进行增加操作。此问题通过构建线段树来高效处理查询和更新操作。
871

被折叠的 条评论
为什么被折叠?



