# 题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1166

# AC代码

```#include<string>
#include<cstdio>
#include<iostream>
#define ll long long

using namespace std;

const int N=5e4+10;
int aa[N],cas,a,b,T,n;
struct TREE
{
int l,r,sum;
}tree[N<<2];
string op;

void Build(int i,int l,int r)
{
tree[i].l=l;
tree[i].r=r;
tree[i].sum=0;
if(l==r)
{
tree[i].sum=aa[l];
return ;
}
int mid=(l+r)>>1;
Build(i<<1,l,mid);
Build(i<<1|1,mid+1,r);
tree[i].sum=tree[i<<1].sum+tree[i<<1|1].sum;
return ;
}
{
if(tree[i].l==tree[i].r)
{
return ;
}
int mid=(tree[i].l+tree[i].r)>>1;
tree[i].sum=tree[i<<1].sum+tree[i<<1|1].sum;
return ;
}
void Sub(int i,int x,int sub)
{
if(tree[i].l==tree[i].r)
{
tree[i].sum-=sub;
return ;
}
int mid=(tree[i].l+tree[i].r)>>1;
if(x<=mid) Sub(i<<1,x,sub);//left
else Sub(i<<1|1,x,sub);
tree[i].sum=tree[i<<1].sum+tree[i<<1|1].sum;
return ;
}
int Query(int i,int l,int r)
{
if(l<=tree[i].l && tree[i].r<=r)
return tree[i].sum;
if(tree[i].l>r || tree[i].r<l)
return 0;
int res=0;
if(l<=tree[i<<1].r) res+=Query(i<<1,l,r);//left
if(r>=tree[i<<1|1].l) res+=Query(i<<1|1,l,r);
return res;
}
int main()
{
scanf("%d",&T);
while(T--)
{
cas++;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&aa[i]);
Build(1,1,n);
printf("Case %d:\n",cas);
while(1)
{
cin>>op;
if(op=="End") break;
scanf("%d%d",&a,&b);