RT,样例过了,然后全WA了。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100010,M=350;
int n,q,a,b,len;
char op;
int w[N];
int add[M],sum[M];
int get(int i){return i/len;}
signed main(){
cin>>n>>q;
len=sqrt(n);
while(q--){
cin>>op>>a>>b;
if(op=='x'){
w[a]+=b;
sum[get(a)]+=b;
continue;
}
int res=0;
if(get(a)==get(b)) for(int i=a;i<=b;i++) res+=w[i]+add[get(i)];
else{
int i=a,j=b;
while(get(i)==get(a)) res+=w[i]+add[get(i)],i++;
while(get(j)==get(b)) res+=w[j]+add[get(j)],j--;
for(int i=get(i);i<=get(j);i++) res+=sum[i];
}
cout<<res<<endl;
}
}