#include<bits/stdc++.h>
using namespace std;
constexpr int N = 1e5 + 1,SQ = sqrt(N) + 1;
int n,m,a[N],t,siz,st[SQ],ed[SQ],pos[N],tag[SQ],sum[SQ];
void updata(int L,int R) {
int p = pos[L],q = pos[R];
if(p == q) {
for(int i=L;i<=R;++i) {
sum[pos[i]] -= (a[i] ^ tag[pos[i]]);
a[i] ^= 1;
}
return ;
}
for(int i=p+1;i<=q-1;++i) tag[i] ^= 1;
for(int i=L;i<=ed[p];++i) {
sum[pos[i]] -= (a[i] ^ tag[pos[i]]);
a[i] ^= 1;
}
for(int i=st[q];i<=R;++i) {
sum[pos[i]] -= (a[i] ^ tag[pos[i]]);
a[i] ^= 1;
}
}
int query(int L,int R) {
int p = pos[L],q = pos[R],res = 0;
if(p == q) {
for(int i=L;i<=R;++i) {
res += (a[i] ^ tag[pos[i]]);
}
return res;
}
for(int i=p + 1;i<=q - 1;++i) {
if(tag[i]) res += siz - sum[i];
else res += sum[i];
}
for(int i=L;i<=ed[p];++i) {
res += (a[i] ^ tag[pos[i]]);
}
for(int i=st[q];i<=R;++i) {
res += (a[i] ^ tag[pos[i]]);
}
return res;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> m;
siz = sqrt(n);
t = n % siz?n/siz + 1:n/siz;
for(int i=1;i<=t;++i) {
st[i] = (i - 1) * siz + 1;
ed[i] = i * siz;
}
ed[t] = n;
for(int i=1;i<=t;++i) {
for(int j=st[i];j<=ed[i];++j) {
pos[j] = i;
}
}
while(m--) {
int opt,x,y;
cin >> opt >> x >> y;
if(opt == 0) {
updata(x,y);
}else {
cout << query(x,y) << '\n';
}
}
return 0;
}