View Code 
#include <stdio.h>
#include <string.h>
int n;
long long a[50005],f,b[50005];
char s[10];
int lowbit (int t)
{
    return t & ( t ^ ( t - 1 ) );
}
int sum(int end)
{
    int s=0;
    while (end>0)
    {
        s+=b[end];
        end-=lowbit(end);
    }
    return s;
}
void plu(int pos ,int num)
{
    while (pos<=n)
    {
        b[pos]+=num;
        pos+=lowbit(pos);
    }
}
int main()
{
    int T,i,j,t,c;
    scanf("%d",&T);
    t=0;
    while (T--)
    {
        ++t;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        scanf("%d",&n);
        for (i=1;i<=n;i++)
            scanf("%lld",&a[i]);
        for (i=1;i<=n;i++)
        {
            int x;
            x=lowbit(i);
            while (x--)
            {
                b[i]+=a[i-x];
            }
        }
        getchar();
        printf("Case %d:\n",t);
        while (scanf("%s",&s) && s[0]!='E')
        {
            scanf("%d%d",&i,&j);
            if (s[0]=='A') plu(i,j);
            else if (s[0]=='S') plu(i,-j);
            else 
            {
                f=sum(j)-sum(i-1);
                printf("%lld\n",f);
            }
        }
    }
    return 0;
posted on 2013-03-20 22:06  Modiz  阅读(128)  评论(0编辑  收藏  举报