很裸很水的树状数组
#include#include #include #include #include #include #include using namespace std;#define N 1000005int c[N],n,m;int sum(int x){ int ret=0; while(x) { ret+=c[x]; x-=x&-x; } return ret;}void add(int x,int d){ while(x<=n) { c[x]+=d; x+=x&-x; }}int main(){ char ch[20]; int i,j,k,a,b; while(~scanf("%d%d",&n,&m)) { for(i=1;i<=n;++i) { scanf("%d",&a); add(i,a); } while(m--) { scanf("%s%d%d",ch,&a,&b); if(ch[0]=='Q') printf("%d\n",sum(b)-sum(a-1)); else add(a,b); } } return 0;}