#include using namespace std; template struct Segt { E ei; T ti; vector dat; vector tag; FTE fte; FTT ftt; FEE fee; Segt(E ei, T ti, FTE a, FTT b, FEE c) : ei(ei), ti(ti), fte(a), ftt(b), fee(c){ dat.assign(2 * n, ei); tag.assign(2 * n, ti); } void build(vector a) { for (int i = 0; i < a.size(); ++i) dat[n + i] = a[i]; for (int i = n - 1; i; --i) dat[i] = fee(dat[i << 1], dat[i << 1 | 1]); } void push(int k) { for (int c = 0; c < 2; ++c) { tag[k << 1 | c] = ftt(tag[k], tag[k << 1 | c]); dat[k << 1 | c] = fte(tag[k], dat[k << 1 | c]); } tag[k] = ti; } void update(T t, int ql, int qr, int lb = 0, int rb = n, int k = 1) { if (qr <= lb || rb <= ql) return; if (ql <= lb && rb <= qr) { tag[k] = ftt(t, tag[k]); dat[k] = fte(t, dat[k]); return; } push(k); int mb = lb + rb >> 1; update(t, ql, qr, lb, mb, k << 1); update(t, ql, qr, mb, rb, k << 1 | 1); dat[k] = fee(dat[k << 1], dat[k << 1 | 1]); } E query(int ql, int qr, int lb = 0, int rb = n, int k = 1) { if (qr <= lb || rb <= ql) return ei; if (ql <= lb && rb <= qr) return dat[k]; push(k); int mb = lb + rb >> 1; return fee(query(ql, qr, lb, mb, k << 1), query(ql, qr, mb, rb, k << 1 | 1)); } }; int main() { ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } typedef struct { int minv; } E; typedef struct { int updv; } T; function fte = [](T f, E e) { return E({ f.updv ? f.updv : e.minv }); }; function ftt = [](T f, T t) { return T({ f.updv ? f.updv : t.updv }); }; function fee = [](E l, E r) { return E({ min(l.minv, r.minv) }); }; Segt<(1 << 17), E, T, decltype(fte), decltype(ftt), decltype(fee)> tree(E({N}), T({0}), fte, ftt, fee); vector> nxt2(17, vector(N, N)); for (int i = N - 1; ~i; --i) { nxt2[0][i] = tree.query(A[i], N + 1).minv; tree.update(T({ i }), A[i], A[i] + 1); } for (int i = 0; i + 1 < nxt2.size(); ++i) { for (int u = 0; u < N; ++u) { int v = nxt2[i][u]; if (v < N) nxt2[i + 1][u] = nxt2[i][v]; } } while (Q--) { int P, L, R; cin >> P >> L >> R; --L; int ans = 1; for (int i = nxt2.size() - 1; ~i; --i) { if (nxt2[i][L] < R) { ans += 1 << i; L = nxt2[i][L]; } } cout << ans << endl; } return 0; }