/*screw_1011*/
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define ll long long int
int lazy[200005];
struct node
{
int a1; ///a1 = lights are in on
int b1; ///b1 = lights are in off
}st[200005];
// qs = querry starting
// qe = querry ending
// ss = segment starting
// se = segment ending
// index = level of the seg tree
int get(int ss,int se,int qs,int qe,int index)
{
if(qs>se || qe<ss)
return 0;
if(lazy[index]!=0)
{
int tmp;
tmp = st[index].a1;
st[index].a1 = st[index].b1;
st[index].b1 = tmp;
if(ss!=se)
{
if(lazy[2*index+1]==0)
lazy[2*index+1] = 1;
else
lazy[2*index+1] = 0;
if(lazy[2*index+2] == 0)
lazy[2*index+2] = 1;
else
lazy[2*index+2] = 0;
}
lazy[index] = 0;
}
if(qs<=ss & qe>=se)
return st[index].a1;
int mid = ss + (se-ss)/2;
return get(ss,mid,qs,qe,2*index+1) + get(mid+1,se,qs,qe,2*index+2);
}
void update(int ss,int se,int qs,int qe,int index)
{
//node needs to be updated or not
if(lazy[index]!=0)
{
//switch karna hai iss index par
int tmp;
tmp = st[index].a1;
st[index].a1 = st[index].b1;
st[index].b1 = tmp;
//if not a leaf node , mark the childs as lazy
if(ss!=se)
{
if(lazy[2*index+1]==0)
lazy[2*index+1] = 1;
else
lazy[2*index+1] = 0;
if(lazy[2*index+2]==0)
lazy[2*index+2] = 1;
else
lazy[2*index+2] = 0;
}
lazy[index] = 0;
}
if(qs>se || qe<ss)
return ;
if(qs<=ss && qe>=se)
{
int tmp1;
tmp1 = st[index].a1;
st[index].a1 = st[index].b1;
st[index].b1 = tmp1;
if(ss!=se)
{
if(lazy[2*index+1]==1)
lazy[2*index+1] = 0;
else
lazy[2*index+1] = 1;
if(lazy[2*index+2]==1)
lazy[2*index+2] = 0;
else
lazy[2*index+2] = 1;
}
return ;
}
int mid = ss + (se-ss)/2;
update(ss,mid,qs,qe,2*index+1);
update(mid+1,se,qs,qe,2*index+2);
st[index].a1 = st[2*index+1].a1 + st[2*index+2].a1;
st[index].b1 = st[2*index+1].b1 + st[2*index+2].b1;
}
void coseg(int ss,int se,int index)
{
if(ss==se)
{
st[index].a1 = 0;
st[index].b1 = 1;
return ;
}
int mid = ss + (se-ss)/2;
coseg(ss,mid,2*index+1);
coseg(mid+1,se,2*index+2);
st[index].a1 = st[2*index+1].a1 + st[2*index+2].a1;
st[index].b1 = st[2*index+1].b1 + st[2*index+2].b1;
}
int main()
{
int t,n,m,p,q,x,ans;
scanf("%d%d",&n,&m);
coseg(0,n-1,0);
while(m--)
{
scanf("%d",&x);
if(x==0)
{
scanf("%d%d",&p,&q);
update(0,n-1,p-1,q-1,0);
}
else
{
scanf("%d%d",&p,&q);
ans = get(0,n-1,p-1,q-1,0);
printf("%d\n",ans);
}
}
return 0;
}
LypzY3Jld18xMDExKi8KI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBNUCBtYWtlX3BhaXIKI2RlZmluZSBQQiBwdXNoX2JhY2sKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwojZGVmaW5lIGxsIGxvbmcgbG9uZyBpbnQKaW50IGxhenlbMjAwMDA1XTsKc3RydWN0IG5vZGUKewoJaW50IGExOyAvLy9hMSA9IGxpZ2h0cyBhcmUgaW4gb24KCWludCBiMTsgLy8vYjEgPSBsaWdodHMgYXJlIGluIG9mZiAKfXN0WzIwMDAwNV07Ci8vIHFzID0gcXVlcnJ5IHN0YXJ0aW5nIAovLyBxZSA9IHF1ZXJyeSBlbmRpbmcKLy8gc3MgPSBzZWdtZW50IHN0YXJ0aW5nCi8vIHNlID0gc2VnbWVudCBlbmRpbmcKLy8gaW5kZXggPSBsZXZlbCBvZiB0aGUgc2VnIHRyZWUKaW50IGdldChpbnQgc3MsaW50IHNlLGludCBxcyxpbnQgcWUsaW50IGluZGV4KQp7CglpZihxcz5zZSB8fCBxZTxzcykKCXJldHVybiAwOwoJaWYobGF6eVtpbmRleF0hPTApCgl7CgkJ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