#include using namespace std; int main(){ int N, Q; cin >> N >> Q; map mp; mp[0] = 0; mp[N + 1] = 0; for (int i = 0; i < Q; i++){ int t; cin >> t; if (t == 1){ int L, R; cin >> L >> R; for (int j : {L, R}){ if (mp.count(j) == 0){ auto itr = prev(mp.lower_bound(j)); int x = (*itr).second; mp[j] = x; } } while (true){ auto itr = mp.lower_bound(L); int p1 = (*itr).first; if (p1 == R){ break; } mp.erase(itr); } mp[L] = 1; for (int j : {L, R}){ auto itr = mp.lower_bound(j); if ((*itr).second == (*prev(itr)).second){ mp.erase(itr); } } } if (t == 2){ int L, R; cin >> L >> R; for (int j : {L, R}){ if (mp.count(j) == 0){ auto itr = prev(mp.lower_bound(j)); int x = (*itr).second; mp[j] = x; } } while (true){ auto itr = mp.lower_bound(L); int p1 = (*itr).first; if (p1 == R){ break; } mp.erase(itr); } mp[L] = 0; for (int j : {L, R}){ auto itr = mp.lower_bound(j); if ((*itr).second == (*prev(itr)).second){ mp.erase(itr); } } } if (t == 3){ int u, v; cin >> u >> v; if (u == v){ cout << 1 << endl; } else { if (u > v){ swap(u, v); } v--; auto itr = prev(mp.upper_bound(u)); if ((*itr).second == 1 && (*next(itr)).first >= v){ cout << 1 << endl; } else { cout << 0 << endl; } } } if (t == 4){ int v; cin >> v; auto itr = prev(mp.lower_bound(v)); if ((*itr).second == 0){ if ((*next(itr)).first == v){ cout << (*next(itr, 2)).first - (*next(itr)).first + 1 << endl; } else { cout << 1 << endl; } } else { cout << (*next(itr)).first - (*itr).first + 1 << endl; } } } }