description: Alice has recently received an array a_1, a_2, ..., a_n for her birthday! She is very proud of her array, and when she showed her friend Bob the array, he was very happy with her present too!
  
  However, soon Bob became curious, and as any sane friend would do, asked Alice to perform q operations of two types on her array:
  
    * 1 x y: update the element a_x to y (set a_x = y). 
    * 2 l r: calculate how many non-decreasing subarrays exist within the subarray [a_l, a_{l+1}, ..., a_r]. More formally, count the number of pairs of integers (p,q) such that l ≤ p ≤ q ≤ r and a_p ≤ a_{p+1} ≤ ... ≤ a_{q-1} ≤ a_q. 
  
  
  
  Help Alice answer Bob's queries!
  
  Input
  
  The first line contains two integers n and q (1 ≤ n, q ≤ 2 ⋅ 10^5) — the size of the array, and the number of queries, respectively.
  
  The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the elements of Alice's array.
  
  The next q lines consist of three integers each. The first integer of the i-th line is t_i, the operation being performed on the i-th step (t_i = 1 or t_i = 2).
  
  If t_i = 1, the next two integers are x_i and y_i (1 ≤ x_i ≤ n; 1 ≤ y_i ≤ 10^9), updating the element at position x_i to y_i (setting a_{x_i} = y_i).
  
  If t_i = 2, the next two integers are l_i and r_i (1 ≤ l_i ≤ r_i ≤ n), the two indices Bob asks Alice about for the i-th query.
  
  It's guaranteed that there is at least one operation of the second type.
  
  Output
  
  For each query of type 2, print a single integer, the answer to the query.
  
  Example
  
  Input
  
  
  5 6
  3 1 4 1 5
  2 2 5
  2 1 3
  1 4 4
  2 2 5
  1 2 6
  2 2 5
  
  
  Output
  
  
  6
  4
  10
  7
  
  Note
  
  For the first query, l = 2 and r = 5, and the non-decreasing subarrays [p,q] are [2,2], [3,3], [4,4], [5,5], [2,3] and [4,5].
solution: #include <bits/stdc++.h>
  using namespace std;
  void IO();
  void _print(long long t) { cerr << t; }
  void _print(string t) { cerr << t; }
  void _print(char t) { cerr << t; }
  void _print(long double t) { cerr << t; }
  void _print(double t) { cerr << t; }
  void _print(unsigned long long t) { cerr << t; }
  template <class T, class V>
  void _print(pair<T, V> p) {
    cerr << "(";
    _print(p.first);
    cerr << ",";
    _print(p.second);
    cerr << ")";
  }
  template <class T>
  void _print(vector<T> v) {
    cerr << "[ ";
    for (T i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T>
  void _print(set<T> v) {
    cerr << "[ ";
    for (T i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T>
  void _print(multiset<T> v) {
    cerr << "[ ";
    for (T i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T, class V>
  void _print(map<T, V> v) {
    cerr << "[ ";
    for (auto i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T, class V>
  void _print(map<T, V, greater<T>> v) {
    cerr << "[ ";
    for (auto i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T>
  void _print(queue<T> q) {
    cerr << "[ ";
    while (q.size()) {
      _print(q.front());
      cerr << " ";
      q.pop();
    }
    cerr << "]";
  }
  long long max(long long a, long long b, long long c = -1e18,
                long long d = -1e18, long long e = -1e18) {
    return max({a, b, c, d, e});
  }
  long long min(long long a, long long b, long long c = 1e18, long long d = 1e18,
                long long e = 1e18) {
    return min({a, b, c, d, e});
  }
  const long long mod = 1e9 + 7;
  long long binPow(long long x, long long y, long long z = mod);
  void P(vector<long long> v);
  string str, pat;
  long long n, m, d, x, y, t, w, h, k, z, s, l, r, u, q;
  vector<long long> ar;
  const long long N = 3e5 + 10;
  struct node {
    long long left, right, cl, cr, tot, len;
    node() { left = right = cl = cr = tot = len = 0; }
    void nodeUpdate(long long y) {
      left = right = y;
      cl = cr = 1;
      len = 1;
      tot = 1;
    }
    void nodeUpdate(node &l, node &r) {
      cl = l.cl;
      cr = r.cr;
      len = l.len + r.len;
      left = l.left;
      right = r.right;
      tot = 0;
      tot += l.tot;
      tot += r.tot;
      if (l.right <= r.left) {
        long long x = (l.cr + r.cl);
        tot += x * (x + 1) / 2;
        tot -= l.cr * (l.cr + 1) / 2 + r.cl * (r.cl + 1) / 2;
        if (l.len == l.cl) {
          cl = l.len + r.cl;
        }
        if (r.len == r.cl) {
          cr = r.len + l.cr;
        }
      }
    }
  };
  struct tree {
    long long n;
    vector<node> v;
    tree(vector<long long> &ar) {
      n = ar.size();
      v.resize(4 * n + 8);
      buildTree(1, 1, n, ar);
    }
    void buildTree(long long root, long long l, long long r,
                   vector<long long> &ar) {
      if (l == r) {
        v[root].nodeUpdate(ar[l - 1]);
        return;
      }
      long long mid = (l + r) / 2;
      buildTree(root * 2, l, mid, ar);
      buildTree(root * 2 + 1, mid + 1, r, ar);
      v[root].nodeUpdate(v[root * 2], v[root * 2 + 1]);
    }
    void Update(long long root, long long l, long long r, long long ind,
                long long val) {
      if (r < ind || ind < l) return;
      if (l == r) {
        v[root].nodeUpdate(val);
        return;
      }
      long long mid = (l + r) / 2;
      if (ind <= mid)
        Update(root * 2, l, mid, ind, val);
      else
        Update(root * 2 + 1, mid + 1, r, ind, val);
      v[root].nodeUpdate(v[root * 2], v[root * 2 + 1]);
    }
    node query(long long root, long long l, long long r, long long x,
               long long y) {
      node temp;
      if (x > r || y < l) return temp;
      if (x <= l && r <= y) return v[root];
      long long mid = (l + r) / 2;
      node left = query(root * 2, l, mid, x, y);
      node right = query(root * 2 + 1, mid + 1, r, x, y);
      temp.nodeUpdate(left, right);
      return temp;
    }
    void Update(long long ind, long long val) { Update(1, 1, n, ind, val); }
    long long query(long long x, long long y) { return query(1, 1, n, x, y).tot; }
  };
  void solve() {
    cin >> n >> q;
    vector<long long> ar(n);
    for (long long &x : ar) cin >> x;
    tree t(ar);
    ;
    while (q--) {
      long long x, y, z;
      cin >> x >> y >> z;
      if (x == 1) {
        t.Update(y, z);
      } else {
        cout << t.query(y, z) << "\n";
      }
    }
  }
  int32_t main() {
    IO();
    long long t = 1;
    while (t--) {
      solve();
    }
    cout.flush();
  }
  long long binPow(long long x, long long p, long long mod) {
    if (p == 1LL) return x % mod;
    if (p == 0LL) return 1 % mod;
    if (x == 1LL) return 1 % mod;
    long long ans = 1;
    while (p > 0) {
      if (p % 2) {
        ans = (ans * x) % mod;
        p--;
      } else {
        x = (x * x) % mod;
        p /= 2;
      }
    }
    return ans;
  }
  void P(vector<long long> v) {
    for (long long x : v) cout << x << " ";
    cout << endl;
  }
  void IO() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(15);
  }
  