#include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int k = 1, t = 1; while (t * 2 <= n - 1) t *= 2, k++; vector> b(n); vector> c(k, vector(n)); auto it = b.end(); for (int i = n - 1; i >= 0; i--) { pair t = { a[i], i }; it = upper_bound(it, b.end(), t); c[0][i] = it == b.end() ? n : it->second; *--it = t; } for (int l = 1; l < k; l++) { for (int i = 0; i < n; i++) { int j = c[l - 1][i]; c[l][i] = j < n ? c[l - 1][j] : n; } } for (int h = 0; h < q; h++) { int t, l, r; cin >> t >> l >> r; l--; int i = l, a = 1; for (int l = k - 1; l >= 0; l--) { int t = c[l][i]; if (t < r) { i = t; a += 1 << l; } } cout << a << '\n'; } return 0; }