#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mind(a,b) (a>b?b:a) #define maxd(a,b) (a>b?a:b) #define absd(x) (x<0?-(x):x) #define pow2(x) ((x)*(x)) #define rep(i,n) for(int i=0; i=0; --i) #define repl(i,s,n) for(int i=s; i<=n; ++i) #define replr(i,s,n) for(int i=n; i>=s; --i) #define repf(i,s,n,j) for(int i=s; i<=n; i+=j) #define repe(e,obj) for(auto e : obj) #define SP << " " << #define COL << " : " << #define COM << ", " << #define ARR << " -> " << #define PNT(STR) cout << STR << endl #define POS(X,Y) "(" << X << ", " << Y << ")" #define DEB(A) " (" << #A << ") " << A #define DEBREP(i,n,val) for(int i=0; i P; typedef pair PI; typedef pair IP; typedef pair PP; typedef priority_queue, greater

> pvqueue; #define N (1 << 17) class SegmentTree { vector data[2*N]; int n0, n; void build(int k, int l, int r, ll *a) { if(l+1 == r) { if(l < n) data[k].push_back(a[l]); return; } int m = (l+r)/2; if(l < m) build(2*k+1, l, m, a); if(m < r) build(2*k+2, m, r, a); int sz = data[2*k+1].size() + data[2*k+2].size(); data[k].reserve(sz); data[k].resize(data[2*k+1].size()); copy(data[2*k+1].begin(), data[2*k+1].end(), data[k].begin()); for(ll x : data[2*k+2]) { if(data[k].size() == 0 || data[k].back() <= x) { data[k].push_back(x); } } for(ll x : data[k]) { } } P _query(ll x, int a, int b, int k, int l, int r) { if(b <= l || r <= a) { return P{x, 0}; } if(a <= l && r <= b) { auto it = lower_bound(data[k].begin(), data[k].end(), x); return P{max(x, data[k].back()), data[k].end() - it}; } int m = (l + r) / 2; P lv = _query(x, a, b, 2*k+1, l, m); P rv = _query(lv.first, a, b, 2*k+2, m, r); return P{rv.first, lv.second + rv.second}; } public: SegmentTree(int n, ll *a) : n(n) { n0 = 1; while(n0 < n) n0 <<= 1; build(0, 0, n0, a); } ll query(int l, int r) { return _query(0, l, r, 0, 0, n0).second; } }; ll a[N]; int main() { int n, q; cin >> n >> q; rep(i, n) cin >> a[i]; SegmentTree st(n, a); while(q--) { int t, l, r; cin >> t >> l >> r; cout << st.query(l-1, r) << endl; } return 0; }