#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

const int MAX=500009;
int sum[MAX<<2];
void pushUp(int root)
{
    sum[root]=sum[root<<1]+sum[root<<1|1];
}
void build(int l,int r,int root)
{
    if(l==r)
    {
        scanf("%d",&sum[root]);
        return ;
    }
    int mid=(l+r)>>1;
    build(l, mid, root<<1);
    build(mid+1, r, root<<1|1);
    pushUp(root);
}
void update(int i,int val,int l,int r,int root)
{
    if(l==i&&r==i)
    {
        sum[root]+=val;
        return ;
    }
    int mid=(l+r)>>1;
    if(i<=mid)
    {
        update(i, val, l, mid, root<<1);
    }
    else
    {
        update(i, val, mid+1, r, root<<1|1);
    }
    pushUp(root);
}

int query(int rootL,int rootR,int l,int r,int root)
{
    if(rootL<=l&&rootR>=r)
    {
        return sum[root];
    }
    int mid=(l+r)>>1;
    int ans=0;
    if(rootL<=mid)
    {
        ans+=query(rootL, rootR, l, mid, root<<1);
    }
    if(rootR>mid)
    {
        ans+=query(rootL, rootR, mid+1, r, root<<1|1);
    }
    return ans;
}

int main()
{
    int k=1;
    int T;
    int n;
    scanf("%d",&T);
    while (T--) {
        scanf("%d",&n);
        build(1, n, 1);
        printf("Case %d:\n",k++);
        char s[20];
        int i,j;
        while (scanf("%s",s)!=EOF) {
            if(s[0]=='E')
                break;
            scanf("%d%d",&i,&j);
            switch (s[0]) {
                case 'A':
                    update(i, j , 1, n, 1);
                    break;
                case 'S':
                    update(i, -j, 1, n, 1);
                    break;
                 case 'Q':
                    printf("%d\n",query(i, j, 1, n, 1));
                    break;
            }
        }
    }
    return 0;
}

相关文章:

  • 2021-08-18
  • 2021-09-24
  • 2021-08-28
  • 2021-08-18
  • 2021-04-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-25
  • 2022-02-09
  • 2021-11-10
  • 2021-11-27
  • 2021-10-30
  • 2022-01-18
相关资源
相似解决方案