N = gets.to_i A = gets.split.map(&:to_i) Q = gets.to_i counter = Array.new(N) { [0, 0] } 1.upto(N - 1) do |i| counter[i][0] = counter[i - 1][0] counter[i][1] = counter[i - 1][1] if A[i - 1] < A[i] counter[i][0] += 1 elsif A[i - 1] > A[i] counter[i][1] += 1 end end Q.times do l, r = gets.split.map(&:to_i) ans = [0, 0] if counter[r][0] == counter[l][0] ans[1] = 1 end if counter[r][1] == counter[l][1] ans[0] = 1 end puts ans.join(' ') end