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 E1567 {
  	static int[] a;
  
  	public static void main(String[] args) throws IOException {
  		Scanner sc = new Scanner(System.in);
  		PrintWriter pw = new PrintWriter(System.out);
  		int n = sc.nextInt();
  		int q = sc.nextInt();
  		int N = 1;
  		while (N < n)
  			N <<= 1;
  		a = new int[N + 1];
  		for (int i = 1; i <= n; i++) {
  			a[i] = sc.nextInt();
  		}
  		SegmentTree sg = new SegmentTree();
  		while (q-- > 0) {
  			if (sc.nextInt() == 1) {
  				int idx = sc.nextInt();
  				int val = sc.nextInt();
  				sg.update_point(idx, val);
  			} else {
  				int l = sc.nextInt();
  				int r = sc.nextInt();
  				pw.println(sg.query(l, r).ans);
  			}
  		}
  		pw.close();
  	}
  
  	static class SegmentTree { // 1-based DS, OOP
  
  		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
  		Node[] sTree;
  
  		SegmentTree() {
  			N = a.length - 1;
  			sTree = new Node[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
  
  			build(1, 1, N);
  		}
  
  		void build(int node, int b, int e) // O(n)
  		{
  			if (b == e)
  				sTree[node] = new Node(b);
  			else {
  				int mid = b + e >> 1;
  				build(node << 1, b, mid);
  				build(node << 1 | 1, mid + 1, e);
  				sTree[node] = new Node(0);
  				sTree[node].merge(sTree[node << 1], sTree[node << 1 | 1]);
  			}
  		}
  
  		void update_point(int index, int val) // O(log n)
  		{
  			a[index] = val;
  			index += N - 1;
  			while (index > 1) {
  				index >>= 1;
  				sTree[index].merge(sTree[index << 1], sTree[index << 1 | 1]);
  			}
  		}
  
  		Node query(int i, int j) {
  			return query(1, 1, N, i, j);
  		}
  
  		Node query(int node, int b, int e, int i, int j) // O(log n)
  		{
  			if (i > e || j < b)
  				return null;
  			if (b >= i && e <= j)
  				return sTree[node];
  			int mid = b + e >> 1;
  			Node q1 = query(node << 1, b, mid, i, j);
  			Node q2 = query(node << 1 | 1, mid + 1, e, i, j);
  			Node res = new Node(0);
  			res.merge(q1, q2);
  			return res;
  		}
  	}
  
  	static class Node {
  		long ans;
  		long prefix;
  		long suffix;
  		int leftBound;
  		int rightBound;
  		int size;
  
  		public Node(int idx) {
  			ans = 1;
  			prefix = 1;
  			suffix = 1;
  			leftBound = idx;
  			rightBound = idx;
  			size = 1;
  		}
  
  		public void clone(Node x) {
  			this.ans = x.ans;
  			this.prefix = x.prefix;
  			this.suffix = x.suffix;
  			this.leftBound = x.leftBound;
  			this.rightBound = x.rightBound;
  			this.size = x.size;
  		}
  
  		public void merge(Node l, Node r) {
  			if (l == null) {
  				clone(r);
  				return;
  			} else if (r == null) {
  				clone(l);
  				return;
  			}
  			ans = l.ans + r.ans;
  			rightBound = r.rightBound;
  			leftBound = l.leftBound;
  			size = l.size + r.size;
  			if (a[l.rightBound] <= a[r.leftBound]) {
  				ans += l.suffix * r.prefix;
  				if (l.prefix == l.size) {
  					prefix = l.prefix + r.prefix;
  				} else {
  					prefix = l.prefix;
  				}
  				if (r.suffix == r.size) {
  					suffix = r.suffix + l.suffix;
  				} else {
  					suffix = r.suffix;
  				}
  			} else {
  				prefix = l.prefix;
  				suffix = r.suffix;
  			}
  		}
  	}
  
  	static class Scanner {
  		BufferedReader br;
  		StringTokenizer st;
  
  		public Scanner(InputStream s) {
  			br = new BufferedReader(new InputStreamReader(s));
  		}
  
  		public Scanner(FileReader f) {
  			br = new BufferedReader(f);
  		}
  
  		public String next() throws IOException {
  			while (st == null || !st.hasMoreTokens())
  				st = new StringTokenizer(br.readLine());
  			return st.nextToken();
  		}
  
  		public int nextInt() throws IOException {
  			return Integer.parseInt(next());
  		}
  
  		public long nextLong() throws IOException {
  			return Long.parseLong(next());
  		}
  
  		public double nextDouble() throws IOException {
  			return Double.parseDouble(next());
  		}
  
  		public int[] nextIntArr(int n) throws IOException {
  			int[] arr = new int[n];
  			for (int i = 0; i < n; i++) {
  				arr[i] = Integer.parseInt(next());
  			}
  			return arr;
  		}
  
  	}
  
  }
  