单点更改增减,区间球和。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int maxn=55555;
int sum[maxn<<2];
void pushup(int rt)
{
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void build(int l, int r, int rt)
{
if(l==r)
{
scanf("%d", &sum[rt]);
return ;
}
int mid=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void update(int p, int add, int l, int r, int rt)
{
if(l==r)
{
sum[rt]+=add;
return ;
}
int mid=(l+r)>>1;
if(p<=mid)update(p, add, lson);
else update(p, add, rson);
pushup(rt);
}
int query(int L, int R, int l, int r, int rt)
{
if(L<=l && R>=r)
return sum[rt];
int mid=(l+r)>>1;
int ret=0;
if(L<=mid)ret+=query(L, R, lson);
if(R>mid)ret+=query(L, R, rson);
return ret;
}
int main()
{
// freopen("in.txt", "r", stdin);
int T, kase=0;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
build(1, n, 1);
char op[10];
printf("Case %d:\n", ++kase);
while(scanf("%s", op))
{
if(op[0]=='E')
break;
int x, y;
scanf("%d%d", &x, &y);
if(op[0]=='A')
update(x, y, 1, n, 1);
if(op[0]=='S')
update(x, -y, 1, n, 1);
if(op[0]=='Q')
printf("%d\n", query(x, y, 1, n, 1));
}
}
return 0;
}