#include using namespace std; #define TRACE(x) cerr << #x << ' ' << x << endl #define FOR(i, a, b) for (int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) #define _ << ' ' << typedef long long llint; typedef long long ll; typedef pair pii; #define fi first #define sec second #define pb push_back const int MAXM = 55; const int MAXN = 100100; const int MAKS = MAXN * MAXM; const int MAXQ = 200100; const int smjerx[] = {0, 0, 1, -1}; const int smjery[] = {1, -1, 0, 0}; struct UN { int par[MAKS]; void init() { REP(i, MAKS) par[i] = i; } int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); } void join(int a, int b) { a = find(a); b = find(b); if (a != b) par[a] = b; } int pitaj(int a, int b) { return (find(a) == find(b)); } }U; int n = 100000; int m = 50; int get(int x, int y) { x--; y--; return x * n + y; } set s[MAXM]; int q, a[MAXQ], b[MAXQ], c[MAXQ], d[MAXQ]; int t[MAXQ]; int tajm[MAKS]; vector v[MAXQ]; int ans[MAXQ]; int main() { scanf("%d",&q); FOR(i, 1, 51) { FOR(j, 1, n + 1) s[i].insert(j); } REP(i, MAKS) tajm[i] = q; REP(i, q) { scanf("%d",&t[i]); scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]); if (t[i] == 0) { if (a[i] > c[i]) swap(a[i], c[i]); if (b[i] > d[i]) swap(b[i], d[i]); FOR(x, a[i], c[i] + 1) { set :: iterator it = s[x].begin(); it = s[x].lower_bound(b[i]); while (it != s[x].end() && (*it) <= d[i]) { tajm[get(x, *it)] = i; v[i].pb({x, *it}); s[x].erase(it); it = s[x].lower_bound(b[i]); } } } } U.init(); for (int i = 0; i < q; i++) { REP(j, (int)v[i].size()) { int x = v[i][j].fi; int y = v[i][j].sec; REP(k, 4) { int nx = x + smjerx[k]; int ny = y + smjery[k]; if (nx <= 0 || ny <= 0 || nx > m || ny > n) continue; if (tajm[get(x, y)] >= tajm[get(nx, ny)]) U.join(get(x, y), get(nx, ny)); } } if (t[i] == 1) ans[i] = U.pitaj(get(a[i], b[i]), get(c[i], d[i])); } REP(i, q) if (t[i] == 1) printf("%d\n",ans[i]); return 0; }