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.*;
  /*
  
  */
   
   public class SegTree{
  	static FastReader sc=null;
  	
  	//neutral element
  	static Data neutral_element = new Data(0,0,0,-1,-1,0);
  	
  	public static void main(String[] args) {
  		sc=new FastReader();
  		PrintWriter out=new PrintWriter(System.out);
  		int n=sc.nextInt(),q=sc.nextInt();
  		int a[]=sc.readArray(n);
  		ST st=new ST(0,n-1,a);
  		
  		while(q-->0) {
  			int op=sc.nextInt();
  			if(op==1) {
  				int id=sc.nextInt()-1,x=sc.nextInt();
  				st.pointUpdate(id, x);
  			}
  			else {
  				int l=sc.nextInt()-1,r=sc.nextInt()-1;
  				Data ans=st.rangeOp(l, r);
  				out.println(ans.cnt);
  			}
  		}
  		out.close();
  		
  	}
  	static class ST{
  		int l,r;
  		ST left,right;
  		Data curr=new Data();
  		
  		ST(int l,int r,int a[]){
  			this.l=l;
  			this.r=r;
  			if(l==r) {
  				curr.preCount=curr.sufCount=curr.len=1;
  				curr.cnt=1;
  				curr.last=curr.first=a[l];
  			}
  			else {
  				int mid=(l+r)/2;
  				left=new ST(l,mid,a);
  				right=new ST(mid+1,r,a);
  				
  				recalc();
  			}
  		}
  		public void recalc() {
  			if(l==r)return;
  			curr=combine(left.curr,right.curr);
  		}
  		
  		public void pointUpdate(int index,int newVal) {
  			if(l==r) {
  				curr.last=curr.first=newVal;
  				return;
  			}
  			else {
  				if(index<=left.r) left.pointUpdate(index, newVal);
  				else right.pointUpdate(index, newVal);
  				recalc();
  			}
  		}
  		
  		//Combination the data  
  		public Data combine(Data a,Data b) {
  			
  			//if one of them is a neutral element return the other
  			if(a.first==-1) return b;
  			if(b.first==-1) return a;
  			
  			
  			int last=b.last,first=a.first;
  			long cnt=a.cnt+b.cnt;
  			int len=a.len+b.len;
  			
  			int preCount=0,sufCount=0;
  			sufCount=b.sufCount;
  			preCount=a.preCount;
  			if(a.last<=b.first) {
  				cnt+=a.sufCount*1L*b.preCount;
  				if(b.len==b.sufCount) {
  					sufCount+=a.sufCount;
  				}
  				if(a.len==a.preCount) {
  					preCount+=b.preCount;
  				}
  			}
  			
  			return new Data(preCount,cnt,sufCount,last,first,len);
  			
  		}
  		
  		public Data rangeOp(int l, int r) {
  			//disjoint case
  			if(this.r<l || this.l>r) return neutral_element;
  			//covers us
  			if(l<=this.l && this.r<=r) return curr;
  			//we dont know
  			return combine(left.rangeOp(l,r),right.rangeOp(l, r));
  		}
  		
  	}
  	
  	//change the Data according to the requirement
  	static class Data{
  		int preCount,sufCount,last,first,len;
  		long cnt;
  
  		Data(){
  			
  		}
  		
  		Data(int preCount, long cnt, int sufCount, int last, int first,int len) {
  			this.preCount = preCount;
  			this.cnt = cnt;
  			this.sufCount = sufCount;
  			this.last = last;
  			this.len=len;
  			this.first = first;
  		}
  		
  		
  	}
  	
  	static int[] ruffleSort(int a[]) {
  		ArrayList<Integer> al=new ArrayList<>();
  		for(int i:a)al.add(i);
  		Collections.sort(al);
  		for(int i=0;i<a.length;i++)a[i]=al.get(i);
  		return a;
  	}
  	
  	static void print(int a[]) {
  		for(int e:a) {
  			System.out.print(e+" ");
  		}
  		System.out.println();
  	}
  	
  	static class FastReader{
  		
  		StringTokenizer st=new StringTokenizer("");
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		
  		String next() {
  			while(!st.hasMoreTokens()) 
  				try {
  					st=new StringTokenizer(br.readLine());
  				}
  			   catch(IOException e){
  				   e.printStackTrace();
  			   }
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  		
  		int[] readArray(int n) {
  			int a[]=new int[n];
  			for(int i=0;i<n;i++)a[i]=sc.nextInt();
  			return a;
  		}
  	}
  	
  	
  }
  
  