import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.TreeMap; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = Long.parseLong(sa[i]); } int q = Integer.parseInt(br.readLine()); int[] l = new int[q]; int[] r = new int[q]; for (int i = 0; i < q; i++) { sa = br.readLine().split(" "); l[i] = Integer.parseInt(sa[0]); r[i] = Integer.parseInt(sa[1]); } br.close(); TreeMap map1 = new TreeMap<>(); TreeMap map2 = new TreeMap<>(); int idx1 = 0; int idx2 = 0; for (int i = 1; i < n; i++) { if (a[i - 1] > a[i]) { map1.put(idx1, i - 1); idx1 = i; } if (a[i - 1] < a[i]) { map2.put(idx2, i - 1); idx2 = i; } } map1.put(idx1, n - 1); map2.put(idx2, n - 1); PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { if (l[i] == r[i]) { pw.println("1 1"); } else { idx1 = map1.floorKey(l[i]); if (r[i] <= map1.get(idx1)) { pw.print("1 "); } else { pw.print("0 "); } idx2 = map2.floorKey(l[i]); if (r[i] <= map2.get(idx2)) { pw.println("1"); } else { pw.println("0"); } } } pw.flush(); } }