#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

struct S {
    int mx;
    vector<int> vec;
};

S op(S a, S b) {
    S res;
    res.mx = max(a.mx, b.mx);
    vector<int> v = a.vec;
    for (int x : b.vec) {
        if (x > a.mx) {
            v.push_back(x);
        }
    }
    res.vec = v;
    return res;
}

S e() {
    return {0, {}};
}

int main() {
    int n, q;
    cin >> n >> q;
    segtree<S, op, e> seg(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        seg.set(i, {a, {a}});
    }
    while (q--) {
        int t, l, r;
        cin >> t >> l >> r;
        l--;
        cout << seg.prod(l, r).vec.size() << endl;
    }
}