func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   void operator>>(istream& is, vector<T>& v) {     for (auto& e : v) {       is >> e;     }   }   template <class T>   void operator<<(ostream& os, const vector<T>& v) {     for (const auto& e : v) {       os << e <<    ;     }     os <<   n ;   }   long long LenToAns(long long len) { return len * (len + 1) / 2; }   struct Node {     int last;     int first;     int pref;     int suff;     int inf;     int size;     long long ans;   };   vector<Node> tree;   int n;   int n_full;   Node MakeNode(int v) { return {v, v, 1, 1, 1, 1, 1}; }   Node MakeNeutral() { return {0, 0, 0, 0, 0, 0, 0}; }   Node Merge(const Node& l, const Node& r) {     Node res;     res.first = l.first;     res.last = r.last;     res.pref = l.pref;     res.suff = r.suff;     res.inf = max(l.inf, r.inf);     res.ans = l.ans + r.ans;     if (l.last <= r.first) {       res.inf = max(res.inf, l.suff + r.pref);       res.ans += LenToAns(l.suff + r.pref);       res.ans -= LenToAns(l.suff);       res.ans -= LenToAns(r.pref);       if (l.pref == l.size) {         res.pref = l.size + r.pref;       }       if (r.pref == r.size) {         res.suff = l.suff + r.size;       }     }     res.size = l.size + r.size;     return res;   }   void Init(const vector<int>& a) {     n_full = 1;     while (n_full < n) {       n_full *= 2;     }     tree.resize(n_full * 2 - 1);     for (int i = 0; i < n; i++) {       tree[n_full + i - 1] = MakeNode(a[i]);     }     for (int i = n_full - 2; i >= 0; i--) {       tree[i] = Merge(tree[2 * i + 1], tree[2 * i + 2]);     }   }   void Set(int i, int v, int xi, int xl, int xr) {     if (xl > i || i >= xr) {       return;     }     if (xr - xl == 1) {       tree[xi] = MakeNode(v);       return;     }     int xm = (xl + xr) / 2;     Set(i, v, xi * 2 + 1, xl, xm);     Set(i, v, xi * 2 + 2, xm, xr);     tree[xi] = Merge(tree[xi * 2 + 1], tree[xi * 2 + 2]);   }   void Set(int i, int v) { Set(i, v, 0, 0, n_full); }   Node Sum(int l, int r, int xi, int xl, int xr) {     if (xl >= r || l >= xr) {       return MakeNeutral();     }     if (l <= xl && xr <= r) {       return tree[xi];     }     int xm = (xl + xr) / 2;     return Merge(Sum(l, r, xi * 2 + 1, xl, xm), Sum(l, r, xi * 2 + 2, xm, xr));   }   long long Sum(int l, int r) {     Node res = Sum(l, r, 0, 0, n_full);     return res.ans;   }   int main() {     int k;     cin >> n >> k;     vector<int> a(n);     cin >> a;     Init(a);     while (k--) {       int q;       cin >> q;       if (q == 1) {         int i, v;         cin >> i >> v;         i--;         Set(i, v);       } else {         int l, r;         cin >> l >> r;         l--;         cout << Sum(l, r) <<   n ;       }     }   }   