import java.io.*; import java.util.*; public class Island { public static int getRoot(int[] union, int component) { while(component != union[component]) { component = union[component]; } return component; } public static boolean same(int[] union, int a, int b) { a = getRoot(union,a); b = getRoot(union,b); return a == b && a != 0; } public static void unite(int[] union, int a, int b) { int rootA = getRoot(union,a); int rootB = getRoot(union,b); union[rootA] = rootB; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int L = Integer.parseInt(br.readLine()); int[][] map = new int[50][100001]; int[] union = new int[200002]; int nextComponent = 1; for (int i = 0; i < L; i++) { String[] parts = br.readLine().split(" "); int x1 = Integer.parseInt(parts[1]); int y1 = Integer.parseInt(parts[2]); int x2 = Integer.parseInt(parts[3]); int y2 = Integer.parseInt(parts[4]); boolean expand = parts[0].equals("0"); if (!expand) { boolean connected = same(union, map[x1][y1], map[x2][y2]); System.out.println(connected ? "1" : "0"); } if (expand) { if (x2 < x1) { int temp = x1; x1 = x2; x2 = temp; } if (y2 < y1) { int temp = y1; y1 = y2; y2 = temp; } union[nextComponent] = nextComponent; Set toUnite = new HashSet(); for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { if (map[x][y] > 0) { toUnite.add(map[x][y]); } map[x][y] = nextComponent; } } for (int x = x1; x <= x2; x++) { if (map[x][y1-1] > 0) { toUnite.add(map[x][y1-1]); } if (map[x][y2+1] > 0) { toUnite.add(map[x][y2+1]); } } for (int y = y1; y <= y2; y++) { if (map[x1-1][y] > 0) { toUnite.add(map[x1-1][y]); } if (map[x2+1][y] > 0) { toUnite.add(map[x2-1][y]); } } for(Integer comp : toUnite) { unite(union, comp, nextComponent); } nextComponent++; } } } }