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: import java.io.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
  import java.util.Arrays;
  import java.util.StringTokenizer;
  import java.io.IOException;
  import java.io.BufferedReader;
  import java.io.FileReader;
  import java.io.InputStreamReader;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   *
   * @author Khater
   */
  public class Main {
      public static void main(String[] args) {
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          Scanner in = new Scanner(inputStream);
          PrintWriter out = new PrintWriter(outputStream);
          ENonDecreasingDilemma solver = new ENonDecreasingDilemma();
          solver.solve(1, in, out);
          out.close();
      }
  
      static class ENonDecreasingDilemma {
          node max;
          node Identity;
  
          public void solve(int testNumber, Scanner sc, PrintWriter pw) {
              int t = 1;
              //  t = sc.nextInt();
              while (t-- > 0) {
                  Identity = new node(0, 0, 0, 0, 0, 1);
                  max = new node(Integer.MAX_VALUE, Integer.MAX_VALUE, 0, 0, 0, 1);
                  int n = sc.nextInt();
                  int q = sc.nextInt();
                  int N = 1;
                  while (N < n) N *= 2;
                  node[] arr = new node[N + 1];
                  Arrays.fill(arr, Identity);
                  for (int i = 1; i <= n; i++) {
                      int val = sc.nextInt();
                      arr[i] = new node(val, val, 1, 1, 1, 1);
                  }
                  arr[0] = max;
                  SegmentTree st = new SegmentTree(arr);
  
                  while (q-- > 0) {
                      int type = sc.nextInt();
                      int x = sc.nextInt();
                      int y = sc.nextInt();
                      if (type == 1) {
                          st.update_point(x, y);
                      } else {
                          pw.println(st.query(x, y).ans);
                      }
                  }
              }
  
          }
  
          public class SegmentTree {
              int N;
              node[] array;
              node[] sTree;
  
              SegmentTree(node[] in) {
                  array = in;
                  N = in.length - 1;
                  sTree = new node[N << 1];        //no. of nodes = 2*N - 1, we add one to cross out index zero
                  build(1, 1, N);
              }
  
              void build(int node, int b, int e) {
                  if (b == e)
                      sTree[node] = array[b];
                  else {
                      int mid = b + e >> 1;
                      build(node << 1, b, mid);
                      build(node << 1 | 1, mid + 1, e);
                      sTree[node] = sTree[node << 1].merge(sTree[node << 1 | 1]);
                  }
              }
  
              void update_point(int index, int val) {
                  index += N - 1;
                  sTree[index] = new node(val, val, 1, 1, 1, 1);
                  while (index > 1) {
                      index >>= 1;
                      sTree[index] = sTree[index << 1].merge(sTree[index << 1 | 1]);
                  }
              }
  
              node query(int i, int j) {
                  return query(1, 1, N, i, j);
              }
  
              node query(int node, int b, int e, int i, int j) {
                  if (i > e)
                      return new node(Integer.MAX_VALUE, Integer.MAX_VALUE, 0, 0, 0, e - b + 1);
                  if (j < b)
                      return new node(0, 0, 0, 0, 0, e - b + 1);
                  if (b >= i && e <= j)
                      return sTree[node];
                  int mid = b + e >> 1;
                  node q1 = query(node << 1, b, mid, i, j);
                  node q2 = query(node << 1 | 1, mid + 1, e, i, j);
                  return q1.merge(q2);
  
              }
  
          }
  
          public class node {
              long l;
              long r;
              long pre;
              long suf;
              long len;
              long ans;
  
              public node(long l, long r, long pre, long suf, long ans, long len) {
                  this.l = l;
                  this.r = r;
                  this.pre = pre;
                  this.suf = suf;
                  this.ans = ans;
                  this.len = len;
              }
  
              public node merge(node o) {
                  node ret = null;
                  if (r <= o.l) {
                      long newPre = pre == len ? pre + o.pre : pre;
                      long newSuf = o.suf == o.len ? o.suf + suf : o.suf;
                      long rem1 = (suf) * (suf + 1) / 2;
                      long rem2 = (o.pre) * (o.pre + 1) / 2;
                      long add = (suf + o.pre) * (suf + o.pre + 1) / 2;
                      ret = new node(l, o.r, newPre, newSuf, ans + o.ans - rem1 - rem2 + add, len + o.len);
                  } else {
                      ret = new node(l, o.r, pre, o.suf, ans + o.ans, len + o.len);
                  }
                  return ret;
              }
  
              public String toString() {
                  return l + " " + r + " " + pre + " " + suf + " " + len + " " + ans;
              }
  
          }
  
      }
  
      static class Scanner {
          StringTokenizer st;
          BufferedReader br;
  
          public Scanner(FileReader r) {
              br = new BufferedReader(r);
          }
  
          public Scanner(InputStream s) {
              br = new BufferedReader(new InputStreamReader(s));
          }
  
          public String next() {
              while (st == null || !st.hasMoreTokens()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
              }
              return st.nextToken();
          }
  
          public int nextInt() {
              return Integer.parseInt(next());
          }
  
      }
  }
  
  