from itertools import accumulate N = int(input()) A = list(map(int, input().split())) UP = [0] * N DOWN = [0] * N for i, a in enumerate(A[1:], start=1): if A[i - 1] > A[i]: UP[i] = UP[i - 1] + 1 else: UP[i] = UP[i - 1] if A[i - 1] < A[i]: DOWN[i] = DOWN[i - 1] + 1 else: DOWN[i] = DOWN[i - 1] UP_acc = [0] + list(accumulate(UP)) DOWN_acc = [0] + list(accumulate(DOWN)) Q = int(input()) for q in range(Q): ans = [] l, r = map(int, input().split()) l, r = l + 1, r + 1 u_base = UP[l - 1] if UP_acc[r] - UP_acc[l - 1] == (r - l + 1) * u_base: ans.append(1) else: ans.append(0) d_base = DOWN[l - 1] if DOWN_acc[r] - DOWN_acc[l - 1] == (r - l + 1) * d_base: ans.append(1) else: ans.append(0) print(*ans, sep=' ')