#include<bits/stdc++.h> using namespace std; int N,c[50005]; int lowbit(int i){ return i&(-i); } void add(int i,int value){ while(i<=N){ c[i] += value; i += lowbit(i); } } int sum(int i){ int sum=0; while(i >0 ){ sum += c[i]; i-=lowbit(i); } return sum; } int main() { int t,Case=0,d; scanf("%d",&t); while(t--){ printf("Case %d:\n",++Case); scanf("%d",&N); memset(c,0,sizeof(c)); for(int i = 1;i <= N;i++){ scanf("%d",&d); add(i,d); } char command[15]; int x,y; while(~scanf("%s",command)&&command[0]!='E'){ scanf("%d%d",&x,&y); if(command[0]=='Q') printf("%d\n",sum(y)-sum(x-1)); else if(command[0]=='A') add(x,y); else add(x,-y); } } return 0; }
hdu 1166 敌兵布阵(树状数组模板)
猜你喜欢
转载自blog.csdn.net/qq_41156122/article/details/80330233
今日推荐
周排行