#include using namespace std; typedef long long ll; const int MX = 52; const int MY = 100002; struct Point { int maxRectStart; int maxRectId; bool flooded; int parent; int rank; }; Point world[MX][MY]; int toid(int x, int y) { return (MY + 1) * x + y; } Point& gid(int id) { int y = id % (MY + 1); int x = id / (MY + 1); return world[x][y]; } void ufFold(int a) { if(gid(a).parent != a) ufFold(gid(a).parent); gid(a).parent = gid(gid(a).parent).parent; } bool ufFind(int a, int b) { ufFold(a); ufFold(b); return gid(a).parent == gid(b).parent; } void ufUnion(int a, int b) { ufFold(a); ufFold(b); gid(a).flooded = true; gid(b).flooded = true; if(gid(gid(a).parent).rank < gid(gid(b).parent).rank) gid(gid(a).parent).parent = gid(b).parent; else if(gid(gid(b).parent).rank < gid(gid(a).parent).rank) gid(gid(b).parent).parent = gid(a).parent; else { gid(gid(b).parent).parent = gid(a).parent; gid(gid(b).parent).rank++; } } void floodTile(int x, int y) { world[x][y].flooded = true; if(x > 0 && world[x-1][y].flooded) ufUnion(toid(x, y), toid(x - 1, y)); if(y > 0 && world[x][y-1].flooded) ufUnion(toid(x, y), toid(x, y - 1)); if(world[x+1][y].flooded) ufUnion(toid(x, y), toid(x + 1, y)); if(world[x][y+1].flooded) ufUnion(toid(x, y), toid(x, y + 1)); } void join(int x1, int y1, int x2, int y2) { for(int x = x1; x <= x2; x++) { floodTile(x, y1); floodTile(x, y2); } for(int y = y1; y <= y2; y++) { floodTile(x1, y); if(x1 < world[x2][y].maxRectStart) { world[x2][y].maxRectStart = x1; world[x2][y].maxRectId = toid(x1, y1); } floodTile(x2, y); } } void connectToRects(int x, int y) { int id = toid(x, y); for(int xx = x + 1; xx < MX; xx++) { if(world[xx][y].maxRectId != -1 && world[xx][y].maxRectStart <= x) ufUnion(id, world[xx][y].maxRectId); } } bool connected(int x1, int y1, int x2, int y2) { connectToRects(x1, y1); connectToRects(x2, y2); if(!world[x1][y1].flooded || !world[x2][y2].flooded) return false; return ufFind(toid(x1, y1), toid(x2, y2)); } int main() { ios::sync_with_stdio(false); int l; cin >> l; for(int x = 0; x < MX; x++) { for(int y = 0; y < MY; y++) { world[x][y].parent = toid(x, y); world[x][y].maxRectStart = 100; world[x][y].maxRectId = -1; } } for(int i = 0; i < l; i++) { int t, x1, y1, x2, y2; cin >> t >> x1 >> y1 >> x2 >> y2; if(t == 0) { if(x1 > x2) swap(x1, x2); if(y1 > y2) swap(y1, y2); join(x1, y1, x2, y2); } else cout << connected(x1, y1, x2, y2) << endl; } }