去你妈蛋超时个鬼
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
struct node{
int l,r,n;
}t[50005];
int ans;
void build(int l,int r,int k){
if(l==r){
t[k].l=l;
t[k].r=r;
t[k].n=0;
return ;
}
t[k].l=l;
t[k].r=r;
t[k].n=0;
int m=(l+r)/2;
build(l,m,2*k);
build(m+1,r,2*k+1);
}
void insert(int x,int cur,int k){
if(t[k].l==t[k].r&&t[k].l==cur){
t[k].n+=x;
return ;
}
int m=(t[k].l+t[k].r)/2;
if(cur<=m)
insert(x,cur,2*k);
else
insert(x,cur,2*k+1);
t[k].n=t[2*k].n+t[2*k+1].n;
}
void find(int a,int b,int k){
if(a<=t[k].l&&t[k].r<=b){
ans+=t[k].n;
return ;
}
int m=(t[k].l+t[k].r)/2;
if(a>m)
find(a,b,2*k+1);
else if(b<=m)
find(a,b,2*k);
else{
find(a,b,2*k);
find(a,b,2*k+1);
}
}
int main(){
int n,m;
scanf("%d",&m);
for(int i=1;i<=m;i++){
cout<<"Case"<<" "<<i<<":"<<endl;
int n;
scanf("%d",&n);
build(1,n,1);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
insert(x,i,1);
}
char a[6];
while(scanf("%s",a)){
ans=0;
if(a[0]=='E')
break;
if(a[0]=='Q'){
int x,y;
cin>>x>>y;
find(x,y,1);
cout<<ans<<endl;
}
else if(a[0]=='A'){
int x,y;
cin>>x>>y;
insert(y,x,1);
}
else {
int x,y;
cin>>x>>y;
insert(-y,x,1);
}
}
}
return 0;
}