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.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.io.*;
  import java.util.*;
   
   
   
  public class Codeforces {
  	
  	static int mod=1000000007;
  	
  	public static void main(String[] args) {
  		FastScanner fs=new FastScanner();
  		PrintWriter out=new PrintWriter(System.out);
  		int n=fs.nextInt(), q=fs.nextInt();
  		int[] a=fs.readArray(n);
  		ST st=new ST(0, n-1);
  		for (int i=0; i<n-1; i++) {
  			if (a[i]>a[i+1]) st.pointUpdate(i, true);
  		}
  		for (int qq=0; qq<q; qq++) {
  			int type=fs.nextInt();
  			if (type==1) {
  				//point update
  				int position=fs.nextInt()-1, value=fs.nextInt();
  				a[position]=value;
  				if (position!=0) {
  //					System.out.println("Setting index "+(position-1)+" to "+(a[position]<a[position-1]));
  					st.pointUpdate(position-1, a[position]<a[position-1]);
  				}
  //				System.out.println("\n\n");
  				if (position!=n-1)
  					st.pointUpdate(position, a[position+1]<a[position]);
  			}
  			else {
  				int l=fs.nextInt()-1, r=fs.nextInt()-1;
  //				System.out.println("Quering "+l+" "+r);
  				long ans=st.rangeQuery(l, r).value();
  				out.println(ans);
  			}
  		}
  		out.close();
  	}
  	
  	static class Data {
  		int leftStraight, rightStraight, size;
  		long middleSum;
  		public Data(int leftStraight, int rightStraight, int size, long middleSum) {
  			this.leftStraight=leftStraight;
  			this.rightStraight=rightStraight;
  			this.size=size;
  			this.middleSum=middleSum;
  		}
  		long value() {
  			if (size==leftStraight)
  				return nC2(leftStraight);
  			return middleSum+nC2(leftStraight) + nC2(rightStraight);
  		}
  		boolean uninterrupted() {
  			return rightStraight==size;
  		}
  		
  		public String toString() {
  			return "{ "+leftStraight+" ... "+middleSum+" ... "+rightStraight+" } size: "+size;
  		}
  	}
  	
  	static Data combine(Data l, Data r) {
  		if (l==null) return r;
  		if (r==null) return l;
  		int newSize=l.size+r.size;
  		int newL=-1;
  		int newR=-1;
  		long newM=-1;
  		if (l.uninterrupted()) {
  			newM=r.middleSum;
  			newL=l.size+r.leftStraight;
  		}
  		else {
  			newL=l.leftStraight;
  		}
  		if (r.uninterrupted()) {
  			newR=r.size+l.rightStraight;
  			newM=l.middleSum;
  		}
  		else {
  			newR=r.rightStraight;
  		}
  		if (newM==-1) {
  			newM=l.middleSum+r.middleSum+nC2(l.rightStraight+r.leftStraight);
  		}
  		Data ans=new Data(newL, newR, newSize, newM);
  //		System.out.println("Combined "+l+" "+r+" to "+ans);
  		return ans;
  	}
  	
  	static long nC2(int n) {
  		return n*(long)(n+1)/2;
  	}
  /*
  [   ]
   O O O O O O 
    | | | | | |
   */
  	static class ST {
  		int leftmost, rightmost;
  		ST lChild, rChild;
  		Data data;
  		public ST(int l, int r) {
  			this.leftmost=l;
  			this.rightmost=r;
  			if (l!=r) {
  				int mid=(l+r)/2;
  				lChild=new ST(l, mid);
  				rChild=new ST(mid+1, r);
  				recalc();
  			}
  			else {
  				data=new Data(1, 1, 1, 0);
  			}
  		}
  		void recalc() {
  			if (leftmost==rightmost) {
  				return;
  			}
  			data=combine(lChild.data, rChild.data);
  		}
  		void pointUpdate(int position, boolean isCutPoint) {
  			if (leftmost==rightmost) {
  				data=new Data(1, isCutPoint?0:1, 1, 0);
  				return; 
  			}
  			if (position<=lChild.rightmost) {
  				lChild.pointUpdate(position, isCutPoint);
  			}
  			else {
  				rChild.pointUpdate(position, isCutPoint);
  			}
  			recalc();
  		}
  		Data rangeQuery(int l, int r) {
  			if (l>rightmost || r<leftmost) return null;
  			if (l<=leftmost && r>=rightmost) return data;
  			Data lAns=lChild.rangeQuery(l, r);
  			Data rAns=rChild.rangeQuery(l, r);
  			return combine(lAns, rAns);
  		}
  	}
  	
  	static long pow(long a,long b) {
  		if(b<0) return 1;
  		long res=1;
  		while(b!=0) {
  			if((b&1)!=0) {
  				res*=a;
  				res%=mod;
  			}
  			a*=a;
  			a%=mod;
  			b=b>>1;
  		}
  		return res;
  	}
  	static long gcd(long  a,long  b) {
  		if(b==0) return a;
  		return gcd(b,a%b);
  	}
  	static long nck(int n,int k) {
  		if(k>n) return 0;
  		long res=1;
  		res*=fact(n);
  		res%=mod;
  		res*=modInv(fact(k));
  		res%=mod;
  		res*=modInv(fact(n-k)); 
  		res%=mod;
  		return res;
  	}
  	static long fact(long n) {
  		long res=1;
  		for(int i=2;i<=n;i++) {
  			res*=i;
  			res%=mod;
  		}
  		return res;
  	}
  	
  	static long modInv(long n) {
  		return pow(n,mod-2);
  	}
  	
  	static void sort(int[] a) {
  		//suffle
  		int n=a.length;
  		Random r=new Random();
  		for (int i=0; i<a.length; i++) {
  			int oi=r.nextInt(n);
  			int temp=a[i];
  			a[i]=a[oi];
  			a[oi]=temp;
  		}
  		
  		//then sort
  		Arrays.sort(a);
  	}
  	
  	// Use this to input code since it is faster than a Scanner
  	static class FastScanner {
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st=new StringTokenizer("");
  		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[] lreadArray(int n) {
  			long a[]=new long[n];
  			for(int i=0;i<n;i++) a[i]=nextLong();
  			return a;
  		}
  		int[] readArray(int n) {
  			int[] a=new int[n];
  			for (int i=0; i<n; i++) a[i]=nextInt();
  			return a;
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
   
  }