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.*;
  import java.util.*;
  
  /**
   * A simple template for competitive programming problems.
   */
  public class Solution {
      //InputReader in = new InputReader("input.txt");
      final InputReader in = new InputReader(System.in);
  
      final PrintWriter out = new PrintWriter(System.out);
  
      void solve() {
          int n = in.nextInt();
          int q = in.nextInt();
          int[] a = in.nextArray(n);
          LST lst = new LST(a);
          while (q-- > 0) {
              int t = in.nextInt();
              if (t == 1) {
                  int i = in.nextInt() - 1;
                  int val = in.nextInt();
                  lst.update(i, i, val);
              } else {
                  int l = in.nextInt();
                  int r = in.nextInt();
                  out.println(lst.query(l - 1, r - 1).ans);
              }
          }
      }
  	class LST {
  		private class Node{
              long ans;
              int fl;
              int ll;
              int length;
              int f;
              int l;
              void leaf(int val) {
                  ans = 1;
                  fl = 1;
                  ll = 1;
                  f = val;
                  l = val;
                  length = 1;
              }
  
              void merge(Node a, Node b) {
                  f = a.f;
                  l = b.l;
                  ans = a.ans + b.ans;
                  if (a.l <= b.f) {
                      ans += (long) a.ll * b.fl;
                  }
                  fl = a.fl;
                  ll = b.ll;
                  if (a.fl == a.length && a.l <= b.f) {
                      fl += b.fl;
                  }
                  if (b.ll == b.length && a.l <= b.f) {
                      ll += a.ll;
                  }
                  length = a.length + b.length;
              }
  
              void split(Node left, Node right) {
              }
  
              void updateSingle(int val) {
                  ans = 1;
                  fl = 1;
                  ll = 1;
                  f = val;
                  l = val;
                  length = 1;
              }
  		}
  
  		private Node[] tree;
  		private int n;
  
  		// ******************************************************************* //
  
  		public LST(int[] arr) {
  			n = arr.length;
  			int ceilLog = 32-Integer.numberOfLeadingZeros(arr.length-1);
  			tree = new Node[1<<(ceilLog+1)];
  			for(int i=0; i<tree.length; i++){
  				tree[i] = new Node();
  			}
  			build(1, 0, arr.length-1, arr);
  		}
  
  		public void update(int ql, int qr, int val) {
  			updateUtil(ql, qr, val, 1, 0, n-1);
  		}
  
  		public Node query(int l, int r) {
  			return queryUtil(l, r, 1, 0, n-1);
  		}
  
  		public void set(int idx, int val) {
  			queryUtil(idx, idx, 1, 0, n-1);
  			set(idx, val, 1, 0, n-1);
  		}
  
  		private void build(int node, int l, int r, int[] arr) {
  			if (l == r) {
  				tree[node].leaf(arr[l]);
  				return;
  			}
  			int m = (l+r+1) / 2;
  			build(2*node, l, m-1, arr);
  			build(2*node + 1, m, r, arr);
  			tree[node].merge(tree[2*node], tree[2*node + 1]);
  		}
  
  		private void set(int idx, int val, int node, int l, int r) {
  			if (l == r) {
  				tree[node].leaf(val);
  				return;
  			}
  			int m = (l+r+1) / 2;
  			if (idx < m) set(idx, val, 2*node, l, m-1);
  			else set(idx, val, 2*node + 1, m, r);
  			tree[node].merge(tree[2*node], tree[2*node + 1]);
  		}
  
  		private void updateUtil(int ql, int qr, int val, int node, int l, int r) {
  			if (qr >= r && ql <= l) {
  				tree[node].updateSingle(val);
  				return;
  			}
  			tree[node].split(tree[2*node], tree[2*node+1]);
  			int mid = (l+r+1) / 2;
  			if(ql < mid) updateUtil(ql, qr, val, 2*node, l, mid-1);
  			if(qr >= mid) updateUtil(ql, qr, val, 2*node + 1, mid, r);
  			tree[node].merge(tree[2*node], tree[2*node + 1]);
  		}
  
  		private Node queryUtil(int ql, int qr, int node, int l, int r) {
  			if (qr >= r && ql <= l) {
  				return tree[node];
  			}
  			tree[node].split(tree[2*node], tree[2*node+1]);
  			int mid = (l+r+1) / 2;
  			Node ln = null;
  			Node rn = null;
  			if(ql < mid) ln = queryUtil(ql, qr, 2*node, l, mid-1);
  			if(qr >= mid) rn = queryUtil(ql, qr, 2*node + 1, mid, r);
  			Node n = new Node();
  
  			if(ln==null)
  				n = rn;
  			else if(rn==null)
  				n = ln;
  			else
  				n.merge(ln, rn);
  
  			return n;
  		}
  
  	}
      private void shuffle(int[] a) {
          int n = a.length;
          Random random = new Random();
          random.nextInt();
          for (int i = 0; i < n; i++) {
              int change = i + random.nextInt(n - i);
              swap(a, i, change);
          }
      }
  
      private static void swap(int[] a, int i, int j) {
          int helper = a[i];
          a[i] = a[j];
          a[j] = helper;
      }
  
      public static void main(final String[] args) throws FileNotFoundException {
          final Solution s = new Solution();
          final Long t1 = System.currentTimeMillis();
          s.solve();
          System.err.println(System.currentTimeMillis() - t1 + " ms");
          s.out.close();
      }
  
      public Solution() throws FileNotFoundException {
      }
  
      private static class InputReader {
          private final InputStream stream;
          private final byte[] buf = new byte[1024];
          private int curChar;
          private int numChars;
          Random r = new Random();
  
          InputReader(final InputStream stream) {
              this.stream = stream;
          }
  
          InputReader(final String fileName) {
              InputStream stream = null;
              try {
                  stream = new FileInputStream(fileName);
              } catch (final FileNotFoundException e) {
                  e.printStackTrace();
              }
              this.stream = stream;
          }
  
          int[] nextArray(final int n) {
              final int[] arr = new int[n];
              for (int i = 0; i < n; i++)
                  arr[i] = nextInt();
              return arr;
          }
  
          int[][] nextMatrix(final int n, final int m) {
              final int[][] matrix = new int[n][m];
              for (int i = 0; i < n; i++)
                  for (int j = 0; j < m; j++)
                      matrix[i][j] = nextInt();
              return matrix;
          }
  
          String nextLine() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              final StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isEndOfLine(c));
              return res.toString();
          }
  
          String nextString() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              final StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          long nextLong() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              long res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          int nextInt() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          double nextDouble() {
              return Double.parseDouble(nextString());
          }
  
          private int read() {
              if (numChars == -1)
                  throw new InputMismatchException();
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (final IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0)
                      return -1;
              }
              return buf[curChar++];
          }
  
          private boolean isSpaceChar(final int c) {
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          private boolean isEndOfLine(final int c) {
              return c == '\n' || c == '\r' || c == -1;
          }
      }
  
  }