#include using namespace std; template struct SegmentTree{ using Func = function; int size; vector seg; const Func merge; const Monoid def; SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){ for(size = 1; size <= n; size <<= 1); seg.assign(size*2, def); } Monoid& operator[] (int i) { return seg[i+size]; }; void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); } void update(int i, Monoid val){ seg[i += size] = val; while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]); } void add(int i, Monoid val){ update(i, val+seg[i+size]); } Monoid get(int a, int b){ Monoid l = def, r = def; for(a += size, b += size; a < b; a >>= 1, b >>= 1){ if(a & 1) l = merge(l, seg[a++]); if(b & 1) r = merge(r, seg[--b]); } return merge(l, r); } }; vector vec[100010]; vector > query[100010]; int main(){ int n, q; cin >> n >> q; int mp[100010]; int a[100010]; SegmentTree seg(n, -1, [](int a, int b){ return max(a, b); }); SegmentTree seg2(n, 0, [](int a, int b){ return a + b; }); for(int i = 0;i < n;i++){ cin >> a[i]; mp[a[i]] = i; } for(int i = 0;i < n;i++){ int g = seg.get(a[i], n+1); if(g != -1){ vec[g].push_back(i); } seg.update(a[i], i); } for(int i = 0;i < q;i++){ int x, l, r; cin >> x >> l >> r; l--; query[l].push_back({r, i}); } for(int i = 0;i < n;i++){ seg2[i] = 1; } seg2.build(); int ans[100010]; for(int i = n-1;i >= 0;i--){ for(int j = 0;j < vec[i].size();j++){ seg2.update(vec[i][j], 0); } for(int j = 0;j < query[i].size();j++){ ans[query[i][j].second] = seg2.get(i, query[i][j].first); } } for(int i = 0;i < n;i++){ cout << ans[i] << endl; } return 0; }