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.DataInputStream;
  import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  
  public class Main {
  
      private static int[] a;
      private static Node[] nodes;
  
      private static void run() throws IOException {
          int n, q;
          n = in.nextInt();
          q = in.nextInt();
          a = new int[n];
          for (int i = 0; i < n; i++) {
              a[i] = in.nextInt();
          }
  
          nodes = new Node[4 * n + 10];
          init(0, n - 1, 1);
  
          for (int ca = 0; ca < q; ca++) {
              int t = in.nextInt();
              int l = in.nextInt();
              int r = in.nextInt();
              if (t == 1) {
                  update(l - 1, r, 1);
              } else {
                  out.println(query(l - 1, r - 1, 1));
              }
          }
      }
  
      private static long query(int left, int right, int p) {
          if (nodes[p].left == left && nodes[p].right == right) {
              return nodes[p].ans;
          }
  
          int mid = (nodes[p].left + nodes[p].right) >> 1;
          if (right <= mid) {
              return query(left, right, p * 2);
          } else if (left > mid) {
              return query(left, right, p * 2 + 1);
          } else {
              long ans = query(left, mid, p * 2) + query(mid + 1, right, p * 2 + 1);
              if (a[nodes[p * 2].right] <= a[nodes[p * 2 + 1].left]) {
                  long left_options = Math.min(nodes[p * 2].right_size, mid - left + 1);
                  long right_options = Math.min(nodes[p * 2 + 1].left_size, right - (mid + 1) + 1);
                  ans += left_options * right_options;
              }
              return ans;
          }
      }
  
      private static void update(int x, int y, int p) {
          if (nodes[p].left == x && nodes[p].right == x) {
              a[x] = y;
              return;
          }
  
          int mid = (nodes[p].left + nodes[p].right) >> 1;
          if (x <= mid) {
              update(x, y, p * 2);
          } else {
              update(x, y, p * 2 + 1);
          }
  
          nodes[p].left_size = get_left_size(p);
          nodes[p].right_size = get_right_size(p);
          nodes[p].ans = nodes[p * 2].ans + nodes[p * 2 + 1].ans + get_ans_in_cross(p);
      }
  
      private static void init(int left, int right, int p) {
          nodes[p] = new Node();
          nodes[p].left = left;
          nodes[p].right = right;
          if (left == right) {
              nodes[p].left_size = 1;
              nodes[p].right_size = 1;
              nodes[p].ans = 1;
              return;
          }
  
          int mid = (left + right) >> 1;
          init(left, mid, p * 2);
          init(mid + 1, right, p * 2 + 1);
  
          nodes[p].left_size = get_left_size(p);
          nodes[p].right_size = get_right_size(p);
          nodes[p].ans = nodes[p * 2].ans + nodes[p * 2 + 1].ans + get_ans_in_cross(p);
      }
  
      private static long get_ans_in_cross(int p) {
          int left_child = p * 2;
          int right_child = left_child + 1;
          if (a[nodes[left_child].right] <= a[nodes[right_child].left]) {
              return nodes[left_child].right_size * nodes[right_child].left_size;
          } else {
              return 0;
          }
      }
  
      private static long get_left_size(int p) {
          int left_child = p * 2;
          int right_child = left_child + 1;
          if (nodes[left_child].left_size == nodes[left_child].get_total_size() && a[nodes[left_child].right] <= a[nodes[right_child].left]) {
              return nodes[left_child].left_size + nodes[right_child].left_size;
          } else {
              return nodes[left_child].left_size;
          }
      }
  
      private static long get_right_size(int p) {
          int left_child = p * 2;
          int right_child = left_child + 1;
          if (nodes[right_child].right_size == nodes[right_child].get_total_size() && a[nodes[left_child].right] <= a[nodes[right_child].left]) {
              return nodes[left_child].right_size + nodes[right_child].right_size;
          } else {
              return nodes[right_child].right_size;
          }
      }
  
      private static class Node {
          int left, right;
          long left_size, right_size, ans;
  
          private int get_total_size() {
              return this.right - this.left + 1;
          }
      }
  
      public static void main(String[] args) throws IOException {
          in = new Reader();
          out = new PrintWriter(new OutputStreamWriter(System.out));
  
  //        int t = in.nextInt();
  //        for (int i = 0; i < t; i++) {
  //        }
          run();
  
          out.flush();
          in.close();
          out.close();
      }
  
      private static int gcd(int a, int b) {
          if (a == 0 || b == 0)
              return 0;
          while (b != 0) {
              int tmp;
              tmp = a % b;
              a = b;
              b = tmp;
          }
          return a;
      }
  
      static final long mod = 1000000007;
  
      static long pow_mod(long a, long b) {
          long result = 1;
          while (b != 0) {
              if ((b & 1) != 0) result = (result * a) % mod;
              a = (a * a) % mod;
              b >>= 1;
          }
          return result;
      }
  
      private static long multiplied_mod(long... longs) {
          long ans = 1;
          for (long now : longs) {
              ans = (ans * now) % mod;
          }
          return ans;
      }
  
      @SuppressWarnings("FieldCanBeLocal")
      private static Reader in;
      private static PrintWriter out;
  
      private static int[] read_int_array(int len) throws IOException {
          int[] a = new int[len];
          for (int i = 0; i < len; i++) {
              a[i] = in.nextInt();
          }
          return a;
      }
  
      private static long[] read_long_array(int len) throws IOException {
          long[] a = new long[len];
          for (int i = 0; i < len; i++) {
              a[i] = in.nextLong();
          }
          return a;
      }
  
      private static void print_array(int[] array) {
          for (int now : array) {
              out.print(now);
              out.print(' ');
          }
          out.println();
      }
  
      private static void print_array(long[] array) {
          for (long now : array) {
              out.print(now);
              out.print(' ');
          }
          out.println();
      }
  
      static class Reader {
          private static final int BUFFER_SIZE = 1 << 16;
          private final DataInputStream din;
          private final byte[] buffer;
          private int bufferPointer, bytesRead;
  
          Reader() {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException {
              final byte[] buf = new byte[1024]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      break;
                  }
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextSign() throws IOException {
              byte c = read();
              while ('+' != c && '-' != c) {
                  c = read();
              }
              return '+' == c ? 0 : 1;
          }
  
          private static boolean isSpaceChar(int c) {
              return !(c >= 33 && c <= 126);
          }
  
          public int skip() throws IOException {
              int b;
              // noinspection ALL
              while ((b = read()) != -1 && isSpaceChar(b)) {
                  ;
              }
              return b;
          }
  
          public char nc() throws IOException {
              return (char) skip();
          }
  
          public String next() throws IOException {
              int b = skip();
              final StringBuilder sb = new StringBuilder();
              while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
                  sb.appendCodePoint(b);
                  b = read();
              }
              return sb.toString();
          }
  
          public int nextInt() throws IOException {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              final boolean neg = c == '-';
              if (neg) {
                  c = read();
              }
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg) {
                  return -ret;
              }
              return ret;
          }
  
          public long nextLong() throws IOException {
              long ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              final boolean neg = c == '-';
              if (neg) {
                  c = read();
              }
              do {
                  ret = ret * 10 + c - '0';
              }
              while ((c = read()) >= '0' && c <= '9');
              if (neg) {
                  return -ret;
              }
              return ret;
          }
  
          public double nextDouble() throws IOException {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              final boolean neg = c == '-';
              if (neg) {
                  c = read();
              }
  
              do {
                  ret = ret * 10 + c - '0';
              }
              while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg) {
                  return -ret;
              }
              return ret;
          }
  
          private void fillBuffer() throws IOException {
              bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
              if (bytesRead == -1) {
                  buffer[0] = -1;
              }
          }
  
          private byte read() throws IOException {
              if (bufferPointer == bytesRead) {
                  fillBuffer();
              }
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException {
              din.close();
          }
  
      }
  }
  