#include <bits/stdc++.h>
using namespace std;
int t[600000], arr[600000], lazy[600000];
int n, q;
void update(int ind, int lo, int hi, int i, int j)
{
if(lazy[ind] == 1){
t[ind] = hi - lo + 1 - t[ind];
if(hi != lo){
lazy[2*ind + 1]^= 1;
lazy[2*ind]^= 1;
}
lazy[ind] = 0;
}
if (lo > hi || lo > j || hi < i)
return;
if (i <= lo && j >= hi) {
t[ind] = hi - lo + 1 - t[ind];
lazy[ind] = 0;
if(lo != hi){
lazy[2*ind]^= 1;
lazy[2*ind + 1]^= 1;
}
return;
}
int mid = (hi + lo) / 2;
update(2 * ind, lo, mid, i, j);
update(2 * ind + 1, mid + 1, hi, i, j);
t[ind] = t[ind*2] + t[ind*2 + 1];
}
int querySegTree(int ind, int lo, int hi, int i, int j)
{
if(lazy[ind] == 1){
t[ind] = hi - lo + 1 - t[ind];
if(lo != hi){
lazy[2*ind + 1]^= 1;
lazy[2*ind]^= 1;
}
lazy[ind] = 0;
}
if (lo > j || hi < i) {
return 0;
}
if (i <= lo && j >= hi) {
return t[ind];
}
int mid = (hi + lo) / 2;
if(i > mid){
return querySegTree(2 * ind + 1, mid + 1, hi, i, j);
}
if(j <= mid){
return querySegTree(2 * ind, lo, mid, i, j);
}
int leftQuery = querySegTree(2 * ind, lo, mid, i, j);
int rightQuery = querySegTree(2 * ind + 1, mid + 1, hi, i, j);
return leftQuery + rightQuery;
}
int main() {
cin>>n>>q;
for(int i = 1; i <= n; i++){
t[i] = 0;
}
while(q--){
int b, s, t;
cin>>b>>s>>t;
s++; t++;
if(b){
cout<<querySegTree(1, 1, n, s, t)<<'\n';
}
else{
update(1, 1, n, s, t);
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCB0WzYwMDAwMF0sIGFycls2MDAwMDBdLCBsYXp5WzYwMDAwMF07CmludCBuLCBxOwogCnZvaWQgdXBkYXRlKGludCBpbmQsIGludCBsbywgaW50IGhpLCBpbnQgaSwgaW50IGopCnsKICAgIGlmKGxhenlbaW5kXSA9PSAxKXsKICAgICAgICB0W2luZF0gPSBoaSAtIGxvICsgMSAtIHRbaW5kXTsKICAgICAgICBpZihoaSAhPSBsbyl7CiAgICAgICAgICAgIGxhenlbMippbmQgKyAxXV49IDE7CiAgICAgICAgICAgIGxhenlbMippbmRdXj0gMTsKICAgICAgICB9CiAgICAgICAgbGF6eVtpbmRdID0gMDsKICAgIH0KICAgIGlmIChsbyA+IGhpIHx8IGxvID4gaiB8fCBoaSA8IGkpICAgICAgICAgICAgICAgCiAgICAgICAgcmV0dXJuOyAgICAgICAgICAgICAgICAgCgogICAgaWYgKGkgPD0gbG8gJiYgaiA+PSBoaSkgICB7ICAgICAgCiAgICAgICAgdFtpbmRdID0gaGkgLSBsbyArIDEgLSB0W2luZF07CiAgICAgICAgbGF6eVtpbmRdID0gMDsKICAgICAgICBpZihsbyAhPSBoaSl7CiAgICAgICAgICAgIGxhenlbMippbmRdXj0gMTsKICAgICAgICAgICAgbGF6eVsyKmluZCArIDFdXj0gMTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgaW50IG1pZCA9IChoaSArIGxvKSAvIDI7ICAgICAgIAoKICAgIHVwZGF0ZSgyICogaW5kLCBsbywgbWlkLCBpLCBqKTsKICAgIHVwZGF0ZSgyICogaW5kICsgMSwgbWlkICsgMSwgaGksIGksIGopOwogICAgdFtpbmRdID0gdFtpbmQqMl0gKyB0W2luZCoyICsgMV07Cn0KCiBpbnQgcXVlcnlTZWdUcmVlKGludCBpbmQsIGludCBsbywgaW50IGhpLCBpbnQgaSwgaW50IGopCnsKICAgIAogICAgaWYobGF6eVtpbmRdID09IDEpewogICAgICAgIHRbaW5kXSA9IGhpIC0gbG8gKyAxIC0gdFtpbmRdOwogICAgICAgIGlmKGxvICE9IGhpKXsKICAgICAgICAgICAgbGF6eVsyKmluZCArIDFdXj0gMTsKICAgICAgICAgICAgbGF6eVsyKmluZF1ePSAxOwogICAgICAgIH0KICAgICAgICBsYXp5W2luZF0gPSAwOwogICAgfQoKICAgICAgICAgICBpZiAobG8gPiBqIHx8IGhpIDwgaSkgIHsgICAgICAgICAgICAgCiAgICAgICAgcmV0dXJuIDA7ICAKfQogICAgaWYgKGkgPD0gbG8gJiYgaiA+PSBoaSkgICB7ICAgICAgCiAgICAgICAgcmV0dXJuIHRbaW5kXTsKICAgIH0KICAgIGludCBtaWQgPSAoaGkgKyBsbykgLyAyOyAgICAgICAKICAgIGlmKGkgPiBtaWQpewogICAgICAgIHJldHVybiBxdWVyeVNlZ1RyZWUoMiAqIGluZCArIDEsIG1pZCArIDEsIGhpLCBpLCBqKTsKCn0KaWYoaiA8PSBtaWQpewogICAgICAgIHJldHVybiBxdWVyeVNlZ1RyZWUoMiAqIGluZCwgbG8sIG1pZCwgaSwgaik7Cn0KICAgIGludCBsZWZ0UXVlcnkgPSBxdWVyeVNlZ1RyZWUoMiAqIGluZCwgbG8sIG1pZCwgaSwgaik7CiAgICBpbnQgcmlnaHRRdWVyeSA9IHF1ZXJ5U2VnVHJlZSgyICogaW5kICsgMSwgbWlkICsgMSwgaGksIGksIGopOwoKICAgIHJldHVybiBsZWZ0UXVlcnkgKyByaWdodFF1ZXJ5Owp9CiAKaW50IG1haW4oKSB7CiAgICBjaW4+Pm4+PnE7CiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CiAgICAgICAgdFtpXSA9IDA7CiAgICB9CiAgICB3aGlsZShxLS0pewogICAgICAgIGludCBiLCBzLCB0OwogICAgICAgIGNpbj4+Yj4+cz4+dDsKICAgICAgICBzKys7IHQrKzsKICAgICAgICBpZihiKXsKICAgICAgICAgICAgY291dDw8cXVlcnlTZWdUcmVlKDEsIDEsIG4sIHMsIHQpPDwnXG4nOwogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgIHVwZGF0ZSgxLCAxLCBuLCBzLCB0KTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQ==