hdu 1166

#include<iostream>
#include<stdio.h>
#include<string.h>

using namespace std;
const int maxn=50000+20;
int c[maxn];
int N;

int lowbit(int x){
    return (x &(-x));
}

void change(int i,int x){
    while(i<=N){
    c[i]+=x;
    i+=lowbit(i);
    }
}


int  getnum(int x){
    int s=0;
    while(x>0){
        s+=c[x];
        x-=lowbit(x);
    }
    return s;
}

int main(){
    int T;
    scanf("%d",&T);
    int counts=0;
    while(T--){
        memset(c,0,sizeof(c));
        scanf("%d",&N);

        for(int i=1;i<=N;i++){
            int y;
            scanf("%d",&y);
            change(i,y);
        }

        char a[10];
        int k,t;
        printf("Case %d:\n",++counts);
        scanf("%s%d%d",a,&k,&t);
        while(a[0]!='E'){
            if(a[0]=='A'){
                change(k,t);
            }
            if(a[0]=='S'){
                change(k,-t);
            }
            if(a[0]=='Q'){
                printf("%d\n",getnum(t)-getnum(k-1));
            }
            scanf("%s%d%d",a,&k,&t);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值