#include using namespace std; typedef long long ll; typedef long double ld; #define rep(i, a, n) for (int i = (a); i < (n); i++) #define per(i, a, n) for (int i = (n) - 1; i >= (a); i--) int Q, inf, R, C; struct Rect { int x1, y1, x2, y2; }; struct DS { DS(void){} deque> q; void disc(int now) { while (q.size() && q.front().second < now) q.pop_front(); } void add(int val, int till) { while (q.size() && q.back().first >= val) q.pop_back(); q.push_back({val, till}); } int mint(void) { if (!q.size())return inf; return q.front().first; } }; struct UF { vector e; UF(int n) : e(n, -1) {} bool same_set(int a, int b) { return find(a) == find(b); } int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); } void join(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (e[a] > e[b]) swap(a, b); e[a] += e[b]; e[b] = a; } }; int code(int a, int b) { return a * C + b; } pair decode(int c) { return {c / C, c % C}; } vector > neigh(int r, int c) { vector > res; for (auto a : (vector>){{0, 1}, {1, 0}, {-1, 0}, {0, -1}}) { int u, v; u = a.first + r; v = a.second + c; if (u >= 0 && u < R && v >= 0 && v < C) res.push_back({u, v}); } return res; } int main(void) { ios_base::sync_with_stdio(false); cin >> Q; inf = Q; R = 54, C = 200010; vector> qs; vector>>> ops(R); rep(r, 0, R) ops[r].resize(C); rep(q, 0, Q) { int t, x1, y1, x2, y2; cin >> t >> x1 >> y1 >> x2 >> y2; x1--, y1--, x2--, y2--; if (!t) { if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); rep(r, x1, x2 + 1) ops[r][y1].push_back({q, y2}); } qs.push_back({(t) ? q : -1, {x1, y1, x2, y2}}); } vector > mint(R); vector> ev(Q + 10); rep(r, 0, R) mint[r].resize(C); rep(r, 0, R) { DS ds; rep(c, 0, C) { ds.disc(c); for (auto a : ops[r][c]) ds.add(a.first, a.second); mint[r][c] = ds.mint(); ev[mint[r][c]].push_back(code(r, c)); } } UF d(R * C); rep(q, 0, Q) { for (auto a : ev[q]) { int r, c; tie(r, c) = decode(a); for (auto n : neigh(r, c)) { int u,v; tie(u, v) = n; int b = code(u, v); if (mint[u][v] <= q) d.join(a, b); } } auto rect = qs[q].second; if (qs[q].first != -1) cout << d.same_set(code(rect.x1, rect.y1), code(rect.x2, rect.y2)) << endl; } }