#include #define FOR(n, a, b) for(int n = (a); n < (b); ++n) #define ALL(x) x.begin(), x.end() #define pb push_back #define st first #define nd second using namespace std; typedef long long ll; typedef pair pint; typedef vector vi; typedef vector vvi; typedef vector vii; bool water[52][100042]; pint parent[52][100042]; int s[52][100042]; set inter[52]; void init () { for (int i=0; i<52; i++) { for (int y=0; y<100042; y++) { inter[i].insert(y); } } for (int x = 0; x<52; x++) { for (int y=0; y<100042; y++) { parent[x][y] = {x,y}; s[x][y] = 1; } } } pint ff(int x, int y) { vector v; while (parent[x][y] != make_pair(x,y)) { int xx = parent[x][y].first; int yy = parent[x][y].second; v.pb({x,y}); x = xx; y = yy; } for (auto aa : v) { parent[aa.first][aa.second] = {x,y}; } return {x,y}; } void uu(int x, int y, int xx, int yy) { auto p1 = ff(x,y); auto p2 = ff(xx,yy); if (s[p1.first][p1.second] > s[p2.first][p2.second]) { s[p1.first][p1.second] += s[p2.first][p2.second]; parent[p2.first][p2.second] = p1; } else { s[p2.first][p2.second] += s[p1.first][p1.second]; parent[p1.first][p1.second] = p2; } } void break_c(int x, int y) { water[x][y] = 1; vector diffs = {{-1,0}, {1,0}, {0,-1}, {0,1}}; for (auto di : diffs) { int xx = x + di.first; int yy = y + di.second; if (0 <= xx && xx <= 50 && 0 <= yy && yy <= 100000 && water[xx][yy]) uu(x,y,xx,yy); } } void br(int x1, int y1, int x2, int y2) { int a = min(x1,x2), b = max(x1,x2), c = min(y1,y2), d = max(y1,y2); for (int x = a; x <= b; x++) { auto int1 = inter[x].lower_bound(c); auto int2 = inter[x].upper_bound(d); for (auto y = int1; y != int2; y++) { break_c(x,*y); } inter[x].erase(int1,int2); } } bool check(int x1, int y1, int x2, int y2) { //cout << water[x1][y1] << " " << water[x2][y2] << " " << (ff(x1,y1) == ff(x2, y2)) << "\n"; return water[x1][y1] && water[x2][y2] && ff(x1,y1) == ff(x2, y2); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); init (); int l; cin >> l; while (l--) { int t,x1,x2,y1,y2; cin >> t >> x1 >> y1 >> x2 >> y2; if (t == 0) { br(x1,y1,x2,y2); } else { cout << check(x1,y1,x2,y2) << '\n'; } } return 0; }