#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define gold 0
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define freopen(x) freopen(x".in", "r", stdin), freopen (x".out", "w", stdout);
#define ex exit(0)
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
typedef long long ll;
typedef pair<int, int> pii;
const int N = (int) 2e5;
const ll M = (ll) 1e8;
const int INF = 2e9;
const ll BIG = 7e17;
int t[N * 4], z[N * 4];
void push(int v, int tl, int tr) {
if (v + v + 1 < N * 4 && z[v] == 1) {
int tm = (tl + tr) >> 1;
z[v + v] = z[v];
z[v + v + 1] = z[v];
t[v + v] = tm - tl + 1 - t[v + v];
t[v + v + 1] = tr - tm - t[v + v + 1];
z[v] = 0;
}
}
int get(int v, int tl, int tr, int l, int r) {
if (l <= tl && r >= tr)
return t[v];
if (l > tr || r < tl)
return 0;
int tm = (tl + tr) >> 1;
push(v, tl, tr);
return get(v + v, tl, tm, l, r) + get(v + v + 1, tm + 1, tr, l, r);
}
void upd(int v, int tl, int tr, int l, int r) {
if (l <= tl && r >= tr) {
z[v] = 1;
t[v] = tr - tl + 1 - t[v];
return;
}
if (l > tr || r < tl) {
return;
}
int tm = (tl + tr) >> 1;
push(v, tl, tr);
upd(v + v, tl, tm, l, r);
upd(v + v + 1, tm + 1, tr, l, r);
t[v] = t[v + v] + t[v + v + 1];
}
int main() {
//fast_io;
int n, m;
cin >> n >> m;
while(m--) {
int t, l, r;
cin >> t >> l >> r;
if (t == 0)
upd(1, 1, n, l, r);
else
cout << get(1, 1, n, l, r) << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAgIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogICAKI2RlZmluZSBmYXN0X2lvIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCksIGNpbi50aWUoMCksI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