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;
  #pragma GCC optimize("Ofast")
  #pragma GCC target("avx,avx2,fma")
  using ll = long long;
  using ull = unsigned long long;
  using ld = long double;
  constexpr ll INF = 2e18;
  constexpr ld EPS = 1e-9;
  constexpr ll MOD = 1e9 + 7;
  struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
      x += 0x9e3779b97f4a7c15;
      x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
      x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
      return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
      static const uint64_t FIXED_RANDOM =
          chrono::steady_clock::now().time_since_epoch().count();
      return splitmix64(x + FIXED_RANDOM);
    }
  };
  template <typename T1, typename T2>
  using safe_map = unordered_map<T1, T2, custom_hash>;
  template <typename T1, typename T2>
  istream &operator>>(istream &istream, pair<T1, T2> &p) {
    return (istream >> p.first >> p.second);
  }
  template <typename T>
  istream &operator>>(istream &istream, vector<T> &v) {
    for (auto &it : v) cin >> it;
    return istream;
  }
  template <typename T1, typename T2>
  ostream &operator<<(ostream &ostream, const pair<T1, T2> &p) {
    return (ostream << p.first << " " << p.second);
  }
  template <typename T>
  ostream &operator<<(ostream &ostream, const vector<T> &c) {
    for (auto &it : c) cout << it << " ";
    return ostream;
  }
  template <typename T>
  void print(T &&t) {
    cout << t << "\n";
  }
  template <typename T, typename... Args>
  void print(T &&t, Args &&...args) {
    cout << t << " ";
    print(forward<Args>(args)...);
  }
  template <typename T>
  int32_t size_i(T &container) {
    return static_cast<int32_t>(container.size());
  }
  long long GCD(long long a, long long b) {
    while (b) {
      a %= b;
      swap(a, b);
    }
    return a;
  }
  long long GCD_extended(long long a, long long b, long long &x, long long &y) {
    x = 1, y = 0;
    long long x1 = 0, y1 = 1, a1 = a, b1 = b;
    while (b1) {
      long long q = a1 / b1;
      tie(x, x1) = make_tuple(x1, x - q * x1);
      tie(y, y1) = make_tuple(y1, y - q * y1);
      tie(a1, b1) = make_tuple(b1, a1 - q * b1);
    }
    return a1;
  }
  long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }
  long long modpow(ll x, long long n, long long m = MOD) {
    ll res = 1;
    while (n > 0) {
      if (n & 1) res = (res * x) % m;
      x = (x * x) % m;
      n >>= 1;
    }
    return res;
  }
  long long modinv(long long x, long long m = MOD) { return modpow(x, m - 2, m); }
  mt19937 rng;
  long long getRandomNumber(long long l, long long r) {
    uniform_int_distribution<long long> dist(l, r);
    return dist(rng);
  }
  void preSolve() {
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());
  }
  template <typename Data, typename Node>
  class SegTree {
    long long n;
    vector<Node> st;
    function<Node(Node, Node)> mergeFn;
  
   public:
    SegTree() = default;
    SegTree(const vector<Data> &data, const function<Node(Node, Node)> &fn) {
      n = data.size();
      st = vector<Node>(4 * n);
      mergeFn = fn;
      build(data, 1, 0, n - 1);
    }
    Node query(long long l, long long r) { return queryImpl(l, r, 1, 0, n - 1); };
    void pointUpdate(long long pos, const Data &val) {
      return pointUpdateImpl(pos, val, 1, 0, n - 1);
    }
  
   private:
    void build(const vector<Data> &data, long long v, long long l, long long r) {
      if (l == r)
        st[v] = data[l];
      else {
        long long mid = (l + r) / 2;
        build(data, 2 * v, l, mid);
        build(data, 2 * v + 1, mid + 1, r);
        st[v] = mergeFn(st[v * 2], st[v * 2 + 1]);
      }
    }
    Node queryImpl(long long l, long long r, long long v, long long nL,
                   long long nR) {
      if (l > r) return Node{};
      if (nL == l && nR == r) return st[v];
      long long mid = (nL + nR) / 2;
      return mergeFn(queryImpl(l, min(r, mid), 2 * v, nL, mid),
                     queryImpl(max(l, mid + 1), r, 2 * v + 1, mid + 1, nR));
    }
    void pointUpdateImpl(long long pos, const Data &val, long long v,
                         long long nL, long long nR) {
      if (nL == nR) {
        st[v] = val;
        return;
      }
      long long mid = (nL + nR) / 2;
      if (pos <= mid)
        pointUpdateImpl(pos, val, 2 * v, nL, mid);
      else
        pointUpdateImpl(pos, val, 2 * v + 1, mid + 1, nR);
      st[v] = mergeFn(st[2 * v], st[2 * v + 1]);
    }
  };
  struct Node {
    long long first, last, pref, suf, len, ans;
    Node() : first(0), last(0), pref(0), suf(0), len(0), ans(0) {}
    Node(long long x) : first(x), last(x), pref(1), suf(1), len(1), ans(1) {}
  };
  Node merge(Node l, Node r) {
    Node ans;
    ans.first = l.first;
    ans.last = r.last;
    ans.len = l.len + r.len;
    ans.ans = l.ans + r.ans;
    ans.pref = l.pref;
    ans.suf = r.suf;
    if (l.last <= r.first) {
      if (l.len == l.pref) ans.pref = l.len + r.pref;
      if (r.len == r.pref) ans.suf = r.len + l.suf;
      ans.ans += l.suf * r.pref;
    }
    return ans;
  }
  void solve(long long tc) {
    long long n, q;
    cin >> n >> q;
    vector<long long> a(n);
    cin >> a;
    SegTree<long long, Node> st(a, [](Node l, Node r) {
      Node ans;
      ans.first = l.first;
      ans.last = r.last;
      ans.len = l.len + r.len;
      ans.ans = l.ans + r.ans;
      ans.pref = l.pref;
      ans.suf = r.suf;
      if (l.last <= r.first) {
        if (l.len == l.pref) ans.pref = l.len + r.pref;
        if (r.len == r.pref) ans.suf = r.len + l.suf;
        ans.ans += l.suf * r.pref;
      }
      return ans;
    });
    while (q--) {
      long long t, x, y;
      cin >> t >> x >> y;
      if (t == 1) {
        x--;
        st.pointUpdate(x, y);
      } else {
        x--;
        y--;
        print(st.query(x, y).ans);
      }
    }
  }
  int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    preSolve();
    long long tests = 1;
    for (long long tt = 1; tt <= tests; tt++) solve(tt);
    return 0;
  }
  