#include<vector>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<math.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 60022
#define lson rood<<1
#define rson rood<<1|1
int w[N];
struct node
{
    int l,r,v,mid;
}a[N<<2];
void q(int rood,int l,int r)
{
    a[rood].l=l;a[rood].r=r;a[rood].mid=(r+l)/2;
    if(l==r)
    {
        a[rood].v=w[l];
        return ;
    }
    q(lson,l,a[rood].mid);
    q(rson,a[rood].mid+1,r);
    a[rood].v=a[lson].v+a[rson].v;
}   
void qq(int rood,int e,int f)
{
    a[rood].v+=f;
    if(a[rood].r==a[rood].l) return ;
    if(a[rood].mid>=e) qq(lson,e,f);
    else qq(rson,e,f);
}
int Q(int rood,int l,int r)
{
    if(a[rood].l==l&&a[rood].r==r)
        return a[rood].v;
    if(a[rood].mid>=r) return Q(lson,l,r);
    else if(a[rood].mid<l) return Q(rson,l,r);
    else
    {
        int x=Q(lson,l,a[rood].mid);
        int y=Q(rson,a[rood].mid+1,r);
        return x+y;
    }
}

int main()
{
    int T,i,e,f,n,t=1;
    char str[30];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i=1;i<=n;i++)
            scanf("%d",&w[i]);
        q(1,1,n);
        printf("Case %d:\n",t++);
        while(scanf("%s",str),strcmp(str,"End"))
        {
            scanf("%d%d",&e,&f);
            if(str[0]=='Q')
            {
                printf("%d\n",Q(1,e,f));
                continue;
            }
            int ans=1;
            if(str[0]=='S')
                ans*=-1;
            f*=ans;
            qq(1,e,f);
        }
    }
    return 0;
}

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

posted on 2016-07-13 15:52  云胡不喜。  阅读(184)  评论(0编辑  收藏  举报