Non-Decreasing Dilemma codeforces solution – Alice has recently received an array a1,a2,…,ana1,a2,…,an for her birthday

 

Non-Decreasing Dilemma codeforces solution


Alice has recently received an array a1,a2,,ana1,a2,…,an 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 qq operations of two types on her array:

  • 11 xx yy: update the element axax to yy (set ax=yax=y).
  • 22 ll rr: calculate how many non-decreasing subarrays exist within the subarray [al,al+1,,ar][al,al+1,…,ar]. More formally, count the number of pairs of integers (p,q)(p,q) such that lpqrl≤p≤q≤r and apap+1aq1aqap≤ap+1≤⋯≤aq−1≤aq.

Help Alice answer Bob’s queries!

Input

The first line contains two integers nn and qq (1n,q21051≤n,q≤2⋅105) — the size of the array, and the number of queries, respectively.

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) — the elements of Alice’s array.

The next qq lines consist of three integers each. The first integer of the ii-th line is titi, the operation being performed on the ii-th step (ti=1ti=1 or ti=2ti=2).

If ti=1ti=1, the next two integers are xixi and yiyi (1xin1≤xi≤n1yi1091≤yi≤109), updating the element at position xixi to yiyi (setting axi=yiaxi=yi).

If ti=2ti=2, the next two integers are lili and riri (1lirin1≤li≤ri≤n), the two indices Bob asks Alice about for the ii-th query.

It’s guaranteed that there is at least one operation of the second type.

Output

For each query of type 22, print a single integer, the answer to the query.

Example Non-Decreasing Dilemma codeforces solution

input Non-Decreasing Dilemma codeforces solution

Copy Non-Decreasing Dilemma codeforces solution

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

Note

For the first query, l=2l=2 and r=5r=5, and the non-decreasing subarrays [p,q][p,q] are [2,2][2,2][3,3][3,3][4,4][4,4][5,5][5,5][2,3][2,3] and [4,5][4,5].


Leave a Comment