Non-Decreasing Dilemma codeforces solution
Alice has recently received an arrayfor 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 performoperations of two types on her array:
- : update the element to (set ).
- : calculate how many non-decreasing subarrays exist within the subarray . More formally, count the number of pairs of integers such that and .
Help Alice answer Bob’s queries!
The first line contains two integersand ( ) — the size of the array, and the number of queries, respectively.
The second line containsintegers ( ) — the elements of Alice’s array.
The nextlines consist of three integers each. The first integer of the -th line is , the operation being performed on the -th step ( or ).
If, the next two integers are and ( ; ), updating the element at position to (setting ).
If, the next two integers are and ( ), the two indices Bob asks Alice about for the -th query.
It’s guaranteed that there is at least one operation of the second type.
For each query of type, 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
For the first query,and , and the non-decreasing subarrays are , , , , and .