rt
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+10;
const ll M=N<<2;
ll n,q,a[N];
struct node{
ll l,r;
ll sum;
}tree[M];
void build(ll u,ll L,ll R){
tree[u].l=L;
tree[u].r=R;
if(L==R){
tree[u].sum=a[L];
return;
}
ll mid=L+(R-L)/2;
build(u<<1,L,mid);
build(u<<1|1,mid+1,R);
tree[u].sum=tree[u<<1].sum+tree[u<<1|1].sum;
}
ll query(ll u,ll L,ll R){
if(R<tree[u].l||L>tree[u].r)return 0;
if(L<=tree[u].l&&R>=tree[u].r)return tree[u].sum;
ll mid=L+(R-L)/2;
return query(u<<1,L,mid)+query(u<<1,mid+1,R);
}
void change(ll u,ll L,ll R){
if(R<tree[u].l||L>tree[u].r)return;
if(L==R&&L==tree[u].l&&R==tree[u].r){
tree[u].sum=L+R-1-tree[u].sum;
return;
}
ll mid=L+(R-L)/2;
change(u<<1,L,mid);
change(u<<1|1,mid+1,R);
tree[u].sum=tree[u<<1].sum+tree[u<<1|1].sum;
}
int main(){
cin>>n>>q;
build(1,1,n);
while(q--){
ll c,x,y;
cin>>c>>x>>y;
if(c==0){
change(1,x,y);
}
if(c==1){
cout<<query(1,x,y)<<endl;
}
}
return 0;
}
回复请@楼主