题目点着
题意:单点修改,区间查询,树状数组
注意输出格式,每组数据之间有回车,最后一组没有
#include<cstdio>
#include<cstring>
#include<iostream>
typedef long long LL;
using namespace std;
const int N=233333;
int n,a[N],T[N];
char st[5];
void add(int k,int num){
while (k<=n){
T[k]+=num;
k+=k&(-k);
}
}
LL sum(int k){
LL s=0;
while (k){
s+=T[k];
k-=k&(-k);
}
return s;
}
int main(){
//freopen("fuck.in","r",stdin);
for (int cas=1;scanf("%d",&n)==1&&n;cas++){
memset(T,0,sizeof(T));
for (int i=1;i<=n;i++){
scanf("%d
",&a[i]);
add(i,a[i]);
}
if (cas>1)puts("");
printf("Case %d:
",cas);
while(scanf("%s",st)&&st[0]!='E'){
int x,y;
scanf("%d%d
",&x,&y);
if (st[0]=='M')printf("%lld
",sum(y)-sum(x-1));
else {add(x,y-a[x]);a[x]=y;}
}
}
return 0;
}