GYM 101350L. All’s Wall That Ends Wall ( 线段树

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

题意

线段树维护即可

AC代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值