CF1567E.Non-Decreasing Dilemma
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice has recently received an array a1,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 q operations of two types on her array:
- 1 x y: update the element ax to y (set ax=y).
- 2 l r: calculate how many non-decreasing subarrays exist within the subarray [al,al+1,…,ar]. More formally, count the number of pairs of integers (p,q) such that l≤p≤q≤r and ap≤ap+1≤⋯≤aq−1≤aq.
Help Alice answer Bob's queries!
爱丽丝最近在生日时收到了一个数组 a1,a2,…,an!她为自己的数组感到非常自豪,当她把数组展示给朋友鲍勃看时,鲍勃也对这份礼物非常满意!
然而,很快鲍勃就产生了好奇,像任何理智的朋友一样,他请爱丽丝对这个数组执行 q 次操作,操作分为两类:
- 1 x y:将元素 ax 更新为 y(即令 ax=y)。
- 2 l r:计算子数组 [al,al+1,…,ar] 中非递减子数组的个数。更准确地说,统计满足 l≤p≤q≤r 且 ap≤ap+1≤⋯≤aq−1≤aq 的整数对 (p,q) 的数量。
请帮助爱丽丝回答鲍勃的查询!
输入格式
The first line contains two integers n and q (1≤n,q≤2⋅105) — the size of the array, and the number of queries, respectively.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — the elements of Alice's array.
The next q lines consist of three integers each. The first integer of the i-th line is ti, the operation being performed on the i-th step (ti=1 or ti=2).
If ti=1, the next two integers are xi and yi (1≤xi≤n; 1≤yi≤109), updating the element at position xi to yi (setting axi=yi).
If ti=2, the next two integers are li and ri (1≤li≤ri≤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.
第一行包含两个整数 n 和 q(1≤n,q≤2⋅105)—— 分别表示数组的大小和查询次数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 表示爱丽丝的数组元素。
接下来的 q 行每行包含三个整数。第 i 行的第一个整数为 ti,表示第 i 步执行的操作(ti=1 或 ti=2)。
若 ti=1,则接下来的两个整数为 xi 和 yi(1≤xi≤n;1≤yi≤109),表示将位置 xi 处的元素更新为 yi(即令 axi=yi)。
若 ti=2,则接下来的两个整数为 li 和 ri(1≤li≤ri≤n),表示鲍勃在第 i 次查询中向爱丽丝询问的两个下标。
保证至少存在一次类型为 2 的操作。
输出格式
For each query of type 2, print a single integer, the answer to the query.
对于每个类型为 2 的查询,输出一个整数,即该查询的答案。
输入输出样例
输入#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
说明/提示
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].
对于第一个查询,l=2 且 r=5,非递减子数组 [p,q] 为 [2,2]、[3,3]、[4,4]、[5,5]、[2,3] 和 [4,5]。
输入解题思路,AI测评打分。不知道怎么写?