CF1567E.Non-Decreasing Dilemma

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

  • 11 xx yy: update the element axa_x to yy (set ax=ya_x = y).
  • 22 ll rr: calculate how many non-decreasing subarrays exist within the subarray [al,al+1,…,ar][a_l, a_{l+1}, \dots, a_r]. More formally, count the number of pairs of integers (p,q)(p,q) such that l≤p≤q≤rl \le p \le q \le r and ap≤ap+1≤⋯≤aq−1≤aqa_p \le a_{p+1} \le \dots \le a_{q-1} \le a_q.

Help Alice answer Bob's queries!

爱丽丝最近在生日时收到了一个数组 a1,a2,…,ana_1, a_2, \dots, a_n!她为自己的数组感到非常自豪,当她把数组展示给朋友鲍勃看时,鲍勃也对这份礼物非常满意!

然而,很快鲍勃就产生了好奇,像任何理智的朋友一样,他请爱丽丝对这个数组执行 qq 次操作,操作分为两类:

  • 11 xx yy:将元素 axa_x 更新为 yy(即令 ax=ya_x = y)。
  • 22 ll rr:计算子数组 [al,al+1,…,ar][a_l, a_{l+1}, \dots, a_r] 中非递减子数组的个数。更准确地说,统计满足 l≤p≤q≤rl \le p \le q \le r 且 ap≤ap+1≤⋯≤aq−1≤aqa_p \le a_{p+1} \le \dots \le a_{q-1} \le a_q 的整数对 (p,q)(p,q) 的数量。

请帮助爱丽丝回答鲍勃的查询!

输入格式

The first line contains two integers nn and qq (1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5) — the size of the array, and the number of queries, respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the elements of Alice's array.

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

If ti=1t_i = 1, the next two integers are xix_i and yiy_i (1≤xi≤n1 \le x_i \le n; 1≤yi≤1091 \le y_i \le 10^9), updating the element at position xix_i to yiy_i (setting axi=yia_{x_i} = y_i).

If ti=2t_i = 2, the next two integers are lil_i and rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le 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.

第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5)—— 分别表示数组的大小和查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示爱丽丝的数组元素。

接下来的 qq 行每行包含三个整数。第 ii 行的第一个整数为 tit_i,表示第 ii 步执行的操作(ti=1t_i = 1 或 ti=2t_i = 2)。

若 ti=1t_i = 1,则接下来的两个整数为 xix_i 和 yiy_i(1≤xi≤n1 \le x_i \le n;1≤yi≤1091 \le y_i \le 10^9),表示将位置 xix_i 处的元素更新为 yiy_i(即令 axi=yia_{x_i} = y_i)。

若 ti=2t_i = 2,则接下来的两个整数为 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n),表示鲍勃在第 ii 次查询中向爱丽丝询问的两个下标。

保证至少存在一次类型为 22 的操作。

输出格式

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

对于每个类型为 22 的查询,输出一个整数,即该查询的答案。

输入输出样例

  • 输入#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=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].

对于第一个查询,l=2l = 2 且 r=5r = 5,非递减子数组 [p,q][p,q] 为 [2,2][2,2]、[3,3][3,3]、[4,4][4,4]、[5,5][5,5]、[2,3][2,3] 和 [4,5][4,5]。

输入解题思路,AI测评打分。不知道怎么写?

首页