#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; struct DisjointSparseTable { using T = int; static T op(const T& x, const T& y) { return max(x, y); } const int n; VV t; template DisjointSparseTable(Itr first, Itr last) : n(distance(first, last)), t(__lg(n) + 1, V(first, last)) { for (int k = 1; k < (int) t.size(); ++k) { for (int i0 = 1 << k; i0 < n; i0 += 1 << k + 1) { for (int i = i0 + 1; i < min(i0 + (1 << k), n); ++i) { t[k][i] = op(t[k][i - 1], t[k][i]); } for (int i = i0 - 2; i >= i0 - (1 << k); --i) { t[k][i] = op(t[k][i], t[k][i + 1]); } } } } T acc(int l, int r) const { assert(l < r); if (l == --r) return t[0][l]; int k = __lg(l ^ r); return op(t[k][l], t[k][r]); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, q; cin >> n >> q; V<> a(n); for (auto&& e : a) cin >> e; DisjointSparseTable dst(begin(a), end(a)); VV<> dp(20, V<>(n)); for (int i = 0; i < n; ++i) { int ok = i + 1, ng = n + 1; while (ng - ok > 1) { int mid = ok + ng >> 1; (dst.acc(i, mid) == a[i] ? ok : ng) = mid; } dp[0][i] = ok; } for (int k = 0; k < 19; ++k) for (int i = 0; i < n; ++i) { dp[k + 1][i] = dp[k][i] == n ? n : dp[k][dp[k][i]]; } while (q--) { int tp; cin >> tp; int l, r; cin >> l >> r, --l; int res = 0; for (int k = 19; k >= 0; --k) { if (dp[k][l] >= r) continue; l = dp[k][l]; res |= 1 << k; } cout << res + 1 << '\n'; } }