样例过了,但是WA,求调,谢谢大佬
祝大佬比赛AK,钱多多,睡眠足
#include <iostream>
#include <cstdio>
using namespace std;
int sum=0,a[(int)1e6]={0};
bool tag[(int)1e6]={0};
int n,m;
void push_down(int pos,int x,int y){
if(x==y||(!tag[pos]))return ;
a[pos*2]=((x+y)/2-x+1)-a[pos*2];
a[pos*2+1]=(y-(x+y)/2+2)-a[pos*2+1];
tag[pos]=0;
tag[pos*2]?tag[pos*2]=0:tag[pos*2]=1;
tag[pos*2+1]?tag[pos*2+1]=0:tag[pos*2+1]=1;
return ;
}
void query(int pos,int x,int y,int l,int r){
push_down(pos,x,y);
if(l<=x&&y<=r){
sum+=a[pos];
return ;
}
if(y>r)query(pos*2,x,(x+y)/2,l,r);
if(x<l)query(pos*2+1,(x+y)/2+1,y,l,r);
return ;
}
void add(int pos,int x,int y,int l,int r){
push_down(pos,x,y);
if(l<=x&&y<=r){
a[pos]=(y-x+1)-a[pos];
tag[pos]?tag[pos]=0:tag[pos]=1;
return ;
}
if(r<y){
add(pos*2,x,(x+y)/2,l,r);
a[pos]=a[pos*2]+a[pos*2+1];
}
if(x<l){
add(pos*2+1,(x+y)/2+1,y,l,r);
a[pos]=a[pos*2]+a[pos*2+1];
}
return ;
}
int main(){
scanf("%d%d",&n,&m);
int x,y,z;
for(int i=0;i<m;i++){
scanf("%d%d%d",&x,&y,&z);
sum=0;
x==0?add(1,y,z,1,n):query(1,y,z,1,n),printf("%d\n",sum);
}
return 0;
}