#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) struct SparseTable { private: vector> st; vector lookup; public: SparseTable(vector& v) { int b = 0,n = v.size(); while ((1<(1<>1]+1; } } int getmax(int l,int r) { int b = lookup[r-l]; return max(st[b][l],st[b][r-(1<> n >> q; vector a(n); vector> b(n); for (int i = 0;i < n;++i) scanf("%d",&a[i]); SparseTable st(a); for (int i = 0;i < n;++i) { int ok = i+1,ng = n+1; while (ng-ok > 1) { int mid = (ok+ng)/2; int v = st.getmax(mid,n); (v > a[i] ? ng : ok) = mid; } if (ok < n) b[i].push_back(ok); } for (int j = 0;j < 20;++j) { for (int i = 0;i < n;++i) { if (b[i].size() == j+1 && b[b[i][j]].size() == j+1) b[i].push_back(b[b[i][j]][j]); } } for (int z = 0;z < q;++z) { int c,l,r; cin >> c >> l >> r; l--; int ans = 1; while (!b[l].empty() && b[l][0] < r) { for (int i = b[l].size()-1;i >= 0;--i) if (b[l][i] < r) { ans += (1< node; public: SegmentTree(vector v) { int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2*n-1,-INF); for (int i = 0;i < sz;++i) node[i+n-1] = v[i]; for (int i = n-2;i >= 0;--i) node[i] = max(node[2*i+1],node[2*i+2]); } void update(int x,int val) { x += (n-1); node[x] = val; while (x > 0) { x = (x-1)/2; node[x] = max(node[2*x+1],node[2*x+2]); } } int getmax(int a,int b,int k = 0,int l = 0,int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return -INF; if (a <= l && r <= b) return node[k]; int vl = getmax(a,b,2*k+1,l,(l+r)/2); int vr = getmax(a,b,2*k+2,(l+r)/2,r); return max(vl,vr); } int find(int a,int b,int x,int k = 0,int l = 0,int r = -1) { if (r < 0) r = n; if (r <= a || b <= l || node[k] <= x) return -1; if (k >= n-1) return k-n+1; int vl = find(a,b,x,2*k+1,l,(l+r)/2); if (vl != -1) return vl; return find(a,b,x,2*k+2,(l+r)/2,r); } void display() { p_ary(node,0,2*n-1,i); } }; int main() { int n,q; cin >> n >> q; vector a(n); vector> b(n); for (int i = 0;i < n;++i) scanf("%d",&a[i]); SegmentTree seg(a); for (int i = 0;i < n;++i) { int v = seg.find(i+1,n,a[i]); if (v > -1) b[i].push_back(v); } for (int j = 0;j < 20;++j) { for (int i = 0;i < n;++i) { if (b[i].size() == j+1 && b[b[i][j]].size() == j+1) b[i].push_back(b[b[i][j]][j]); } } for (int z = 0;z < q;++z) { int c,l,r; cin >> c >> l >> r; l--; int ans = 1; while (!b[l].empty() && b[l][0] < r) { for (int i = b[l].size()-1;i >= 0;--i) if (b[l][i] < r) { ans += (1<