import sys input = sys.stdin.buffer.readline N, Q = map(int, input().split()) A = tuple(map(int, input().split())) stk = [] doubling = [[None] * N for _ in range(N.bit_length())] for i, a in enumerate(A): while stk and stk[-1][1] <= a: j, b = stk.pop() doubling[0][j] = i stk.append((i, a)) for k in range(N.bit_length() - 1): for i in range(N): if doubling[k][i] is not None: doubling[k + 1][i] = doubling[k][doubling[k][i]] for _ in range(Q): _, L, R = map(int, input().split()) L -= 1 R -= 1 ans = 1 for k in range(N.bit_length() - 1, -1, -1): if doubling[k][L] is not None and doubling[k][L] <= R: L = doubling[k][L] ans += 1 << k print(ans)