#include<bits/stdc++.h>
#define lc p*2
#define rc p*2+1
using namespace std;
const int maxn=1e5+1;
int n,m,w[maxn];
struct node{
int l,r,sum,add;
}tree[maxn*4];
inline void build (int p,int l,int r){
tree[p].l=l;
tree[p].r=r;
if(l==r){
tree[p].sum=w[l];
return;
}
int m=(l+r)>>1;
if(l<=m)build(lc,l,m);
if(r>m)build(rc,m+1,r);
tree[p].sum=tree[lc].sum+tree[rc].sum;
}
inline void xg(int p) {
tree[p].sum=tree[p].r-tree[p].l+1-tree[p].sum;
tree[p].add^=1;
}
inline void pushup(int p){
tree[p].sum=tree[lc].sum+tree[rc].sum;
}
inline void pushdown(int p){
if(tree[p].add){
xg(lc);
xg(rc);
tree[p].add=0;
}
}
inline void update(int p,int x,int y){
if(x<=tree[p].l&&tree[p].r<=y){
xg(p);
return;
}
pushdown(p);
int m=(tree[p].l+tree[p].r)>>1;
if(x<=m)update(lc,x,y);
if(x>m) update(rc,x,y);
pushup(p);
}
inline int query(int p,int x,int y){
if(x<=tree[p].l&&tree[p].r<=y){
return tree[p].sum;
}
pushdown(p);
int m=(tree[p].l+tree[p].r)>>1;
int sum=0;
if(x<=m)sum+=query(lc,x,y);
if(y>m)sum+=query(rc,x,y);
return sum;
}
int main(){
cin>>n>>m;
build(1,1,n);
while(m--){
int c,a,b;
cin>>c>>a>>b;
if(c==0) update(1,a,b);
else cout<<query(1,a,b)<<"\n";
}
}