#include using namespace std; int op(int l, int r){return min(l, r);} int e(){return 1 << 30;} int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q, M = 100005, l, r, g; cin >> N >> Q; vector a(N); g = __lg(N); vector> dp(g + 1, vector(N + 1, N)); for(auto &&v : a) cin >> v; atcoder::segtree seg(vector(M, N)); for(int i = N - 1; i >= 0; i--){ dp[0][i] = seg.prod(a[i] + 1, M); seg.set(a[i], i); } for(int i = 0; i < g; i++){ for(int j = 0; j < N; j++){ dp[i + 1][j] = dp[i][dp[i][j]]; } } while(Q--){ cin >> l >> l >> r; l--; int ans = 0; for(int i = g; i >= 0; i--){ if(dp[i][l] < r){ l = dp[i][l]; ans |= 1 << i; } } cout << ++ans << '\n'; } }