#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, Q = map(int, readline().split()) A = [0] + list(map(int, readline().split())) + [N + 1] stack = [N + 1] next_high = [N + 1] * (N + 2) for n in range(N, -1, -1): x = A[n] while x > A[stack[-1]]: stack.pop() next_high[n] = stack[-1] stack.append(n) dp = [None] * 17 dp[0] = next_high for n in range(1, 17): prev = dp[n - 1] dp[n] = [prev[prev[i]] for i in range(N + 2)] def solve(): _, L, R = map(int, readline().split()) ret = 1 for n in range(16, -1, -1): m = dp[n][L] if m <= R: ret += 1 << n L = m return ret answers = (solve() for _ in range(Q)) print('\n'.join(map(str, answers)))