308740: CF1567E. Non-Decreasing Dilemma
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Non-Decreasing Dilemma
题意翻译
有一个长度为 $n$ 的数列 $a$,你需要对其进行 $q$ 次操作,操作有两种类型,按如下格式给出: - `1 x y`:将 $a_x$ 变成 $y$。 - `2 l r`:询问位置在 $[l,r]$ 之间的不下降子串有多少个。形式化地说,你需要求出满足下列条件的数对 $(p,q)$ 的个数: - $l\leqslant p\leqslant q\leqslant r$。 - $\forall i\in[p,q),a_i\leqslant a_{i+1}$。 数据范围: - $1\leqslant n,q\leqslant 2\times 10^5$。 - $1\leqslant a_i\leqslant 10^9$。 - 对于操作 $1$,$1\leqslant x\leqslant n$,$1\leqslant y\leqslant 10^9$。 - 对于操作 $2$,$1\leqslant l\leqslant r\leqslant n$。 Translated by Eason_AC 2021.9.6题目描述
Alice has recently received an array $ a_1, a_2, \dots, 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}, \dots, a_r] $ . More formally, count the number of pairs of integers $ (p,q) $ such that $ l \le p \le q \le r $ and $ a_p \le a_{p+1} \le \dots \le a_{q-1} \le a_q $ . Help Alice answer Bob's queries!输入输出格式
输入格式
The first line contains two integers $ n $ and $ q $ ( $ 1 \le n, q \le 2 \cdot 10^5 $ ) — the size of the array, and the number of queries, respectively. The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 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 \le x_i \le n $ ; $ 1 \le y_i \le 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 \le l_i \le r_i \le 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.
输出格式
For each query of type $ 2 $ , print a single integer, the answer to the query.
输入输出样例
输入样例 #1
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
输出样例 #1
6
4
10
7