①注意c数组需要初始化为0;
②输入数据时利用函数,而不是直接向数组输入数据
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int N = 50010;
int c[N], n, T;
int lowbit(int x){
return x&(-x);
}
void update(int x, int y, int n){
for(int i = x; i <= n; i += lowbit(i)){
c[i] += y;
}
}
int getsum(int x){
int ans = 0;
for(int i = x; i ; i -= lowbit(i)){
ans += c[i];
}
return ans;
}
int main()
{
int a, b, z;
string s;
scanf("%d",&T);
for(int u = 1;u <= T; u ++ ){
scanf("%d",&n);
memset(c, 0, (n+1)<<2);
for(int i = 1; i <= n; i ++){
cin>>z;
update(i, z, n);
}
cout<<"Case"<<" "<<u<<":"<<endl;
while(1){
cin>>s;
if(s[0]== 'E'){
break;
}
scanf("%d%d",&a, &b);
if(s[0] == 'A'){
update(a, b, n);
}
else if(s[0] == 'S'){
update(a, -b, n);
}
else if(s[0] == 'Q'){
cout<<getsum(b) - getsum(a - 1)<<endl;
}
}
}
return 0;
}