CF1567E.Non-Decreasing Dilemma

普及/提高-

通过率:0%

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 lpqrl \le p \le q \le r and apap+1aq1aqa_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 nn and qq ( 1n,q21051 \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 ( 1ai1091 \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 ( 1xin1 \le x_i \le n ; 1yi1091 \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 ( 1lirin1 \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.

输出格式

For each query of type 22 , 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

说明/提示

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] .

首页