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.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.StringTokenizer;
  
  public class taske {
  	public static void main(String[] args) {
  		FastScanner in = new FastScanner();
  		PrintWriter out = new PrintWriter(System.out);
  		int n = in.nextInt(), q = in.nextInt();
  		int a[] = new int[n];
  		for (int i = 0; i < n; i++) a[i] = in.nextInt();
  		SegmentTree sol = new SegmentTree(a);
  		for (int qq = 0; qq < q; qq++) {
  			int t = in.nextInt();
  			if (t == 1) {
  				int pos = in.nextInt() - 1, val = in.nextInt();
  				sol.update(1, 0, n-1, pos, val);
  			} else {
  				int l = in.nextInt() - 1, r = in.nextInt() - 1;
  				out.println(sol.query(1, 0, n-1, l, r).total);
  			}
  		}
  		out.flush();
  	}
  
  	static class SegmentTree {
  		int n;
  		int a[];
  		Vertex st[];
  		SegmentTree(int aa[]) {
  			n = aa.length;
  			a = aa;
  			st = new Vertex[4*n + 100];
  			for (int i = 0; i < st.length; i++) st[i] = new Vertex();
  			build(1, 0, n-1);
  		}
  		Vertex merge(Vertex x, Vertex y) {
  			Vertex ans = new Vertex();
  			ans.len = x.len + y.len;
  			ans.left_element = x.left_element;
  			ans.right_element = y.right_element;
  			//updating left and right
  			if (x.total == x.len * (x.len + 1) / 2 && x.right_element <= y.left_element) {
  				ans.left = x.len + y.left;
  			} else {
  				ans.left = x.left;
  			}
  			if (y.total == y.len * (y.len + 1) / 2 && x.right_element <= y.left_element) {
  				ans.right = y.len + x.right;
  			} else {
  				ans.right = y.right;
  			}
  			// updating total
  			ans.total = x.total + y.total;
  			if (x.right_element <= y.left_element) {
  				ans.total -= x.right * (x.right + 1) / 2;
  				ans.total -= y.left * (y.left + 1) / 2;
  				long full_len = x.right + y.left;
  				ans.total += full_len * (full_len + 1) / 2;
  			}
  			return ans;
  		}
  		void build(int nn, int l, int r) {
  			if (l == r) {
  				st[nn] = new Vertex();
  				st[nn].total = 1;
  				st[nn].left = st[nn].right = st[nn].len = 1;
  				st[nn].left_element = st[nn].right_element = a[l];
  				return;
  			}
  			int mid = (l+r) / 2;
  			build(2*nn, l, mid);
  			build(2*nn + 1, mid+1, r);
  			st[nn] = merge(st[2*nn], st[2*nn + 1]);
  		}
  		void update(int nn, int l, int r, int i, int x) {
  			if (i > r || i < l) return;
  			if (l == r) {
  				st[nn] = new Vertex();
  				st[nn].total = 1;
  				st[nn].left = st[nn].right = st[nn].len = 1;
  				st[nn].left_element = st[nn].right_element = x;
  				return;
  			}
  			int mid = (l+r) / 2;
  			update(2*nn, l, mid, i, x);
  			update(2*nn + 1, mid+1, r, i, x);
  			st[nn] = merge(st[2*nn], st[2*nn + 1]);
  		}
  		Vertex query(int nn, int l, int r, int i, int j) {
  			if (l >= i && r <= j) return st[nn];
  			if (i > r || j < l) {
  				Vertex ans = new Vertex();
  				ans.len = -1;
  				return ans;
  			}
  			int mid = (l+r) / 2;
  			Vertex ll = query(2*nn, l, mid, i, j);
  			Vertex rr = query(2*nn + 1, mid+1, r, i, j);
  			if (ll.len == -1) return rr;
  			if (rr.len == -1) return ll;
  			return merge(ll, rr);
  		}
  	}
  
  	static class Vertex {
  		long total, left, right, len;
  		int left_element, right_element;
  	}
  
  	static class FastScanner {
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer tok = new StringTokenizer("");
  		String next() {
  			while(!tok.hasMoreTokens()) {
  				try {
  					tok = new StringTokenizer(br.readLine());
  				} catch (Exception e) {
  					e.printStackTrace();
  				}
  			}
  			return tok.nextToken();
  		}
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  		float nextFloat() {
  			return Float.parseFloat(next());
  		}
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
  	}
  }
  