#include<bits/stdc++.h>
using namespace std;
int n,m,op,x,y;
struct st{
int lc,rc,v,la,le;
}xd[800010];
void build(int root,int l,int r){
xd[root].lc=l;
xd[root].rc=r;
xd[root].le=r-l+1;
xd[root].la=0;
if(l==r){
xd[root].v=xd[root].le;
}
else{
int mid=(l+r)/2;
build(root*2,l,mid);
build(root*2+1,mid+1,r);
xd[root].v=xd[root*2].v+xd[root*2+1].v;
}
return ;
}
void pushdown(int root){
xd[root*2].la=(xd[root*2].la^1);
xd[root*2+1].la=(xd[root*2+1].la^1);
xd[root*2].v=xd[root*2].le-xd[root*2].v;
xd[root*2+1].v=xd[root*2+1].le-xd[root*2+1].v;
xd[root].la=0;
return ;
}
void xg(int root,int l,int r){
if(l<=xd[root].lc&&xd[root].rc<=r){
xd[root].la=(xd[root].la^1);
xd[root].v=xd[root].le-xd[root].v;
return ;
}
if(l>xd[root].rc||xd[root].lc>r) return ;
if(xd[root].la) pushdown(root);
xg(root*2,l,r);
xg(root*2+1,l,r);
xd[root].v=xd[root*2].v+xd[root*2+1].v;
return ;
}
int cx(int root,int l,int r){
if(l<=xd[root].lc&&xd[root].rc<=r){
return xd[root].v;
}
if(l>xd[root].rc||r<xd[root].lc) return 0;
if(xd[root].la) pushdown(root);
return cx(root*2,l,r)+cx(root*2+1,l,r);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
build(1,1,n);
for(int i=1;i<=m;i++){
cin>>op>>x>>y;
if(op==0){
xg(1,x,y);
}
else{
cout<<cx(1,x,y)<<"\n";
}
}
return 0;
}