树状数组的模板题目,直接套书上公式就可以了,貌似用不用long long 都能过。
最近要玩命了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define MAXD 200000 + 10
int n;
int arr[MAXD];
int C[MAXD];
int lowbit(int x){
return x & -x;
}
LL Sum(int x){
LL ret = 0;
while(x > 0){
ret += C[x];
x -= lowbit(x);
}
return ret;
}
void Add(int x,int d){
while(x <= n){
C[x] += d;
x += lowbit(x);
}
return ;
}
int main(){
int Case = 1;
while(scanf("%d",&n) && n){
memset(C,0,sizeof(C));
if(Case > 1)
printf("\n");
printf("Case %d:\n",Case++);
for(int i = 1 ; i <= n ; i++){
scanf("%d",&arr[i]);
Add(i,arr[i]);
}
char str[10L];
while(scanf("%s",str)){
if(strcmp(str,"END") == 0)
break;
int x,y;
scanf("%d%d",&x,&y);
if(str[0] == 'S'){
int cost = y - arr[x];
arr[x] = y;
Add(x,cost);
}
else if(str[0] == 'M'){
LL Y = Sum(y);
LL X = Sum(x);
printf("%d\n",Y - X + arr[x]);
}
}
}
return 0;
}