#include "bits/stdc++.h" using namespace std; using ll = long long; using Vi = vector; using Pii = pair; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i,b,e) for (int i=(b); i < (e); i++) #define each(a,x) for(auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) #define endl "\n" struct FAU{ Vi G; FAU(int n = 0) { init(n);} void init( int n) { G.assign(n,-1);} int size(int i) {return -G[find(i)];} int find( int i ){ return G[i] < 0 ? i : G[i] = find(G[i]); } bool join( int i, int j){ i = find(i); j = find(j); if( i == j) return false; if( G[i] > G[j] ) swap(i,j); G[i] += G[j]; G[j] = i; return true; } }; struct Cmp { bool operator()(Pii l, Pii r) const { return l.y < r.y || (l.y == r.y && l.x < r.x); } }; const int X = 51, Y = 100001; FAU fau; setS[52]; int nr[X+1][Y+1]; bool water[X+1][Y+1]; void query(){ int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; int nr1 = nr[x1][y1]; int nr2 = nr[x2][y2]; cout << ( fau.find(nr1) == fau.find(nr2) ) << endl; } void set_insert( int line, int y ) { auto pair1 = *(--S[line].lower_bound({-3,y})); auto pair2 = *(S[line].lower_bound({-3,y})); //cout << pair1.y << " " << y << " " << pair2.x << endl; S[line].erase(pair1); S[line].erase(pair2); if( pair1.y + 1 == y && y+1 == pair2.x ) { S[line].insert( {pair1.x, pair2.y}); return; } if( pair1.y + 1 == y) { S[line].insert({pair1.x,y}); S[line].insert(pair2); return; } if( y+1 == pair2.x ) { S[line].insert(pair1); S[line].insert({y,pair2.y}); return; } S[line].insert(pair1); if(y > pair1.y && y < pair2.x) S[line].insert({y,y}); S[line].insert(pair2); } void insert_line(int line, int y1, int y2){ while( y1 <= y2 ){ if( water[line][y1] ) { y1 = (*S[line].lower_bound({-3,y1})).y + 1; }else { water[line][y1] = 1; if( water[line-1][y1] ) fau.join( nr[line][y1], nr[line-1][y1]); if( water[line+1][y1] ) fau.join( nr[line][y1], nr[line+1][y1]); if( water[line][y1-1] ) fau.join( nr[line][y1], nr[line][y1-1]); if( water[line][y1+1] ) fau.join( nr[line][y1], nr[line][y1+1]); set_insert(line,y1); y1++; } } } void insert(){ int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; if( x1 > x2 ) swap( x1,x2 ); if( y1 > y2 ) swap( y1,y2 ); for( int i = x1; i <= x2; i++ ) { insert_line(i,y1,y2); } } void solve(){ for( int i = 0; i<=X; i++){ S[i].insert({-2,-2}); S[i].insert({Y+10,Y+10}); } int count = 0; for( int i = 0; i <= X; i++ ){ for( int j = 0; j<= Y; j++ ){ nr[i][j] = count; count++; } } fau.init(count); int l; cin >> l; for( int i = 0; i < l; i++ ){ int t; cin >> t; if( t == 0 ){ insert(); }else { query(); } } } int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18); solve(); return 0; }