rt
#include <bits/stdc++.h>
using namespace std;
int n,q,tree[300005],t[300005];
void push_down(int k,int l,int r){
int mid=(l+r)>>1;
if(t[k]%2!=0){
tree[k*2]=(mid-l+1)-tree[k*2],t[k*2]+=1;
tree[k*2+1]=(r-mid)-tree[k*2+1],t[k*2+1]+=1;
}
t[k]=0;
}
void change(int k,int x,int y,int a,int b){
if(x>=a && y<=b){
t[k]+=1;
tree[k]=(y-x+1)-tree[k];
return ;
}
int mid=(x+y)>>1;
push_down(k,x,y);
if(a<=mid) change(k*2,x,mid,a,b);
if(b>mid) change(k*2+1,mid+1,y,a,b);
tree[x]=tree[x*2]+tree[x*2+1];
}
int merge(int k,int x,int y,int a,int b){
if(x>=a && y<=b){
return tree[k];
}
int mid=(x+y)>>1;
push_down(k,x,y);
int res=0;
if(a<=mid) res+=merge(k*2,x,mid,a,b);
if(b>mid) res+=merge(k*2+1,mid+1,y,a,b);
return res;
}
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=q;i++){
int t,a,b;
scanf("%d%d%d",&t,&a,&b);
if(t==0){
change(1,1,n,a,b);
}else{
printf("%d\n",merge(1,1,n,a,b));
}
}
return 0;
}