/*
HDU 1166
敌兵布阵
单点更新
区间求和
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define lson (pos<<1)
#define rson (pos<<1|1)
const int maxn = 55555;
int sum[maxn << 2];
void pushup(int pos){
sum[pos] = sum[lson] + sum[rson];
}
void build(int l,int r,int pos){
if(l == r){
scanf("%d",&sum[pos]);
return;
}
int mid = (l + r) >> 1;
build(l,mid,lson);
build(mid + 1,r,rson);
pushup(pos);
}
void update(int L,int R,int m,int pos,int d){
if(L == R){
sum[pos] += d;
return;
}
int mid = (L + R) >> 1;
if(m <= mid)
update(L,mid,m,lson,d);
else
update(mid + 1,R,m,rson,d);
pushup(pos);
}
int query(int L,int R,int l,int r,int pos){
if(l <= L && R <= r)
return sum[pos];
int mid = (L + R) >> 1;
int ans = 0;
if(l <= mid)
ans += query(L,mid,l,r,lson);
if(r > mid)
ans += query(mid + 1,R,l,r,rson);
return ans;
}
int Case = 1;
int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
build(1,n,1);
char op[10];
printf("Case %d:\n",Case++);
while(scanf("%s",op) && op[0] != 'E'){
int a,b;
if(op[0] == 'A'){
scanf("%d%d",&a,&b);
update(1,n,a,1,b);
}
else if(op[0] == 'S'){
scanf("%d%d",&a,&b);
update(1,n,a,1,-b);
}
else{
scanf("%d%d",&a,&b);
printf("%d\n",query(1,n,a,b,1));
}
}
}
return 0;
}
HDU 1166
最新推荐文章于 2019-10-25 00:01:04 发布