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.util.*;
  import java.io.*;
  
  public class Main {
      public static void main(String args[]) {new Main().run();}
  
      FastReader in = new FastReader();
      PrintWriter out = new PrintWriter(System.out);
      void run() {
          work();
          out.flush();
      }
      long mod=1000000007;
      long gcd(long a,long b) {
          return a==0?b:gcd(b%a,a);
      }
      long inf=Long.MAX_VALUE/3;
      int[] pre;
      int[] suf;
      long[] sum;
      int[] A;
      void work() {
          int n=ni(),q=ni();
          A=nia(n);
          pre=new int[n<<2];
          suf=new int[n<<2];
          sum=new long[n<<2];
          build(1,0,n-1);
          while(q-->0){
              int t=ni();
              if(t==1){
                  int idx=ni()-1;
                  int v=ni();
                  A[idx]=v;
                  add(1,idx,v,0,n-1);
              }else{
                  int s=ni()-1,e=ni()-1;
                  long[] ret=query(1,s,e,0,n-1);
                  out.println(ret[0]);
              }
          }
      }
  
      private void build(int node, int l, int r) {
          if(l==r){
              sum[node]=1;
              pre[node]=1;
              suf[node]=1;
              return;
          }
          int m=(l+r)/2;
          build(node<<1,l,m);
          build(node<<1|1,m+1,r);
          sum[node]=sum[node<<1]+sum[node<<1|1];
          pre[node]=pre[node<<1];
          suf[node]=suf[node<<1|1];
          if(A[m]<=A[m+1]){
              sum[node]-=count(pre[node<<1|1])+count(suf[node<<1]);
              sum[node]+=count(pre[node<<1|1]+suf[node<<1]);
              if(m-l+1==pre[node<<1]){
                  pre[node]=pre[node<<1]+pre[node<<1|1];
              }
              if(r-m==suf[node<<1|1]){
                  suf[node]=suf[node<<1|1]+suf[node<<1];
              }
          }
      }
  
      private void add(int node, int idx, long v, int l, int r) {
          if(l==r){
              return;
          }
          int m=(l+r)/2;
          if(idx<=m){
              add(node<<1,idx,v,l,m);
          }
          if(idx>m){
              add(node<<1|1,idx,v,m+1,r);
          }
          sum[node]=sum[node<<1]+sum[node<<1|1];
          pre[node]=pre[node<<1];
          suf[node]=suf[node<<1|1];
          if(A[m]<=A[m+1]){
              sum[node]-=count(pre[node<<1|1])+count(suf[node<<1]);
              sum[node]+=count(pre[node<<1|1]+suf[node<<1]);
              if(m-l+1==pre[node<<1]){
                  pre[node]=pre[node<<1]+pre[node<<1|1];
              }
              if(r-m==suf[node<<1|1]){
                  suf[node]=suf[node<<1|1]+suf[node<<1];
              }
          }
      }
  
      long count(long c){
          return c*(c+1)/2;
      }
  
      private long[] query(int node, int s, int e, int l, int r) {
          if(s<=l&&e>=r){
              return new long[]{sum[node],pre[node],suf[node]};
          }
          int m=(l+r)/2;
          long[] ret=null;
          if(m>=s){
              ret=query(node<<1,s,e,l,m);
          }
          if(m+1<=e){
              long[] ret2=query(node<<1|1,s,e,m+1,r);
              if(ret==null) ret=ret2;
              else{
                  ret=merge(ret,ret2,l,r);
              }
          }
          return ret;
      }
  
      private long[] merge(long[] ret1, long[] ret2, int l, int r) {
          long[] ret=new long[3];
          ret[0]+=ret1[0]+ret2[0];
          ret[1]=ret1[1];
          ret[2]=ret2[2];
          int m=(l+r)/2;
          if(A[m]<=A[m+1]){
              ret[0]-=ret1[2]*(ret1[2]+1)/2+ret2[1]*(ret2[1]+1)/2;
              ret[0]+=(ret1[2]+ret2[1])*(ret1[2]+ret2[1]+1)/2;
              if(m-l+1==ret1[1]){
                  ret[1]=ret1[1]+ret2[1];
              }
              if(r-m==ret2[2]){
                  ret[2]=ret2[2]+ret1[2];
              }
          }
          return ret;
      }
  
      @SuppressWarnings("unused")
      private ArrayList<Integer>[] ng(int n, int m) {
          ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
          for(int i=0;i<n;i++) {
              graph[i]=new ArrayList<>();
          }
          for(int i=1;i<=m;i++) {
              int s=in.nextInt()-1,e=in.nextInt()-1;
              graph[s].add(e);
              graph[e].add(s);
          }
          return graph;
      }
  
      private ArrayList<long[]>[] ngw(int n, int m) {
          ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
          for(int i=0;i<n;i++) {
              graph[i]=new ArrayList<>();
          }
          for(int i=1;i<=m;i++) {
              long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
              graph[(int)s].add(new long[] {e,w});
              graph[(int)e].add(new long[] {s,w});
          }
          return graph;
      }
  
      private int ni() {
          return in.nextInt();
      }
  
      private long nl() {
          return in.nextLong();
      }
      private double nd() {
          return in.nextDouble();
      }
      private String ns() {
          return in.next();
      }
  
      private long[] na(int n) {
          long[] A=new long[n];
          for(int i=0;i<n;i++) {
              A[i]=in.nextLong();
          }
          return A;
      }
  
      private int[] nia(int n) {
          int[] A=new int[n];
          for(int i=0;i<n;i++) {
              A[i]=in.nextInt();
          }
          return A;
      }
  }
  
  class FastReader
  {
      BufferedReader br;
      StringTokenizer st;
      InputStreamReader input;//no buffer
      public FastReader()
      {
          br=new BufferedReader(new InputStreamReader(System.in));
      }
  
      public FastReader(boolean isBuffer)
      {
          if(!isBuffer){
              input=new InputStreamReader(System.in);
          }else{
              br=new BufferedReader(new InputStreamReader(System.in));
          }
      }
  
      public boolean hasNext(){
          try{
              String s=br.readLine();
              if(s==null){
                  return  false;
              }
              st=new StringTokenizer(s);
          }catch(IOException e){
              e.printStackTrace();
          }
          return true;
      }
  
      public String next()
      {
          if(input!=null){
              try {
                  StringBuilder sb=new StringBuilder();
                  int ch=input.read();
                  while(ch=='\n'||ch=='\r'||ch==32){
                      ch=input.read();
                  }
                  while(ch!='\n'&&ch!='\r'&&ch!=32){
                      sb.append((char)ch);
                      ch=input.read();
                  }
                  return sb.toString();
              }catch (Exception e){
                  e.printStackTrace();
              }
          }
          while(st==null || !st.hasMoreElements())//回车，空行情况
          {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
  
      public int nextInt()
      {
          return (int)nextLong();
      }
  
      public long nextLong() {
          try {
              if(input!=null){
                  long ret=0;
                  int b=input.read();
                  while(b<'0'||b>'9'){
                      b=input.read();
                  }
                  while(b>='0'&&b<='9'){
                      ret=ret*10+(b-'0');
                      b=input.read();
                  }
                  return ret;
              }
          }catch (Exception e){
              e.printStackTrace();
          }
          return Long.parseLong(next());
      }
  
      public double nextDouble()
      {
          return Double.parseDouble(next());
      }
  }