服了,心态炸了,不想调了。
#include<bits/stdc++.h>
using namespace std;
int n,m,op,x,y;
int d[40000005];
void push_up(int p){
d[p]=d[p<<1]+d[p<<1|1];
}
void update(int l,int r,int p,int ad,int s){
if(l==s&&r==s){
d[p]+=ad;
return;
}
int mid=(l+r)>>1;
if(s<=mid) update(l,mid,p<<1,ad,s);
if(s>mid) update(mid+1,r,p<<1|1,ad,s);
push_up(p);
}
int getsum(int l,int r,int p,int s,int t){
if(l>=s&&r<=t){
return d[p];
}
int mid=(l+r)>>1,ans=0;
if(s<=mid) ans+=getsum(l,mid,p<<1,s,t);
if(t>mid) ans+=getsum(mid+1,r,p<<1|1,s,t);
return ans;
}
int main(){
cin>>n>>m;
while(m--){
cin>>op;
if(op==0){
cin>>x>>y;
update(1,n,1,1,x);
if(y<n) update(1,n,1,-1,y+1);
}else{
cin>>x;
cout<<getsum(1,n,1,1,x)<<endl;
}
}
return 0;
}