#include using namespace std; struct Problem_D{ set> S; Problem_D(int N) { S.insert({N + 1, N + 1}); } void insert(int L, int R){ int l, r; auto it = S.lower_bound({L, -1}); while(it->second <= R){ tie(r, l) = *it; S.erase(it); L = min(L, l); R = max(R, r); it = S.lower_bound({L, -1}); } S.insert({R, L}); } void erase(int L, int R){ int l, r; auto it = S.lower_bound({L + 1, -1}); while(it->second < R){ tie(r, l) = *it; S.erase(it); if(l < L) S.insert({L, l}); if(R < r) S.insert({r, R}); it = S.lower_bound({L + 1, -1}); } } int size(int v){ auto it = S.lower_bound({v, -1}); if(it->second <= v && v <= it->first) return it->first - it->second + 1; return 1; } bool same(int v, int u){ if(u < v) swap(u, v); auto it = S.lower_bound({v, -1}); return (it->second <= v && u <= it->first); } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q; cin >> N >> Q; assert(2 <= N && N <= 1000000000); assert(1 <= Q && Q <= 200000); Problem_D uf(N); int type, L, R, v, u; while(Q--){ cin >> type; if(type <= 2){ cin >> L >> R; assert(1 <= L && L <= N); assert(1 <= R && R <= N); assert(L < R); if(type == 1) uf.insert(L, R); else uf.erase(L, R); }else if(type == 3){ cin >> u >> v; assert(1 <= u && u <= N); assert(1 <= v && v <= N); cout << (uf.same(u, v) ? 1 : 0) << '\n'; }else{ cin >> v; assert(1 <= v && v <= N); cout << uf.size(v) << '\n'; } } }