CF2184G.Nastiness of Segments

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Andrey remembered that he has nn blocks numbered from 11 to nn. On the block with number ii, there is initially an integer aia_i written. He arranged them in a row in increasing order of their numbers: first is the block with number 11, then the block with number 22, and so on, with the block with number nn at the end.

For a certain segment of consecutive blocks [l,r][l, r] (1≤l≤r≤n1 \le l \le r \le n), we call an integer d (0≤d≤r−l)d\ (0 \le d \le r-l) nasty if min⁡(al,al+1,…,al+d)=d\min(a_l, a_{l+1}, \ldots, a_{l+d}) = d.

Andrey is very curious, so he wants to perform qq operations of one of two types:

  1. Change the number aia_i written on the ii-th block to xx.
  2. Determine the nastiness of the segment [l, r] (1≤l≤r≤n)[l,\ r]\ (1 \le l \le r \le n). The nastiness of the segment refers to the number of nasty numbers d (0≤d≤r−l)d\ (0 \le d \le r-l) for the given segment.

Andrey couldn't figure out how to process these queries quickly, so he turned to you for help. Help him perform the actions described above!

安德烈记得自己有 nn 个编号从 11 到 nn 的方块。在编号为 ii 的方块上,初始时写有一个整数 aia_i。他将这些方块按编号升序排成一行:最前面是编号为 11 的方块,接着是编号为 22 的方块,依此类推,最后是编号为 nn 的方块。

对于某个连续的方块区间 [l,r][l, r](其中 1≤l≤r≤n1 \le l \le r \le n),若整数 dd(满足 0≤d≤r−l0 \le d \le r-l)使得

min⁡(al,al+1,…,al+d)=d,\min(a_l, a_{l+1}, \ldots, a_{l+d}) = d,

则称 dd 是“讨厌的”(nasty)。

安德烈非常好奇,因此他希望执行 qq 次操作,每次操作为以下两种类型之一:

  1. 将第 ii 个方块上的数 aia_i 修改为 xx;
  2. 查询区间 [l, r][l,\ r](其中 1≤l≤r≤n1 \le l \le r \le n)的“讨厌度”(nastiness)。该区间讨厌度定义为:满足上述条件的讨厌整数 dd(0≤d≤r−l0 \le d \le r-l)的个数。

安德烈无法快速处理这些查询,于是向你求助。请帮助他完成上述操作!

输入格式

The first line contains an integer tt (1≤t≤104)(1 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers nn and qq (1≤n,q≤2⋅105)(1 \le n, q \le 2 \cdot 10^5) — the number of blocks and the number of operations, respectively.

The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤2⋅105)(1 \le a_i \le 2 \cdot 10^5) — the initial numbers written on the blocks.

The following qq lines describe the operations to be performed.

Each line starts with an integer idxidx (1≤idx≤2)(1 \le idx \le 2) — the type of operation.

If idx=1idx = 1, then two integers ii (1≤i≤n)(1 \le i \le n) and xx (1≤x≤2⋅105)(1 \le x \le 2 \cdot 10^5) follow — the description of the first type of operation.

If idx=2idx = 2, then two integers ll and rr (1≤l≤r≤n)(1 \le l \le r \le n) follow — the description of the second type of operation.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5, and the sum of qq over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5)—— 分别表示方块的数量和操作的数量。

下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5)—— 表示方块上初始写下的数字。

接下来的 qq 行描述将要执行的操作。

每行以一个整数 idxidx(1≤idx≤21 \le idx \le 2)开头—— 表示操作类型。

若 idx=1idx = 1,则随后是两个整数 ii(1≤i≤n1 \le i \le n)和 xx(1≤x≤2⋅1051 \le x \le 2 \cdot 10^5)—— 描述第一类操作。

若 idx=2idx = 2,则随后是两个整数 ll 和 rr(1≤l≤r≤n1 \le l \le r \le n)—— 描述第二类操作。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5,且所有测试用例中 qq 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, for each operation of the second type, print an integer representing the nastiness of the segment.

对于每个测试用例,针对每种第二类操作,输出一个整数,表示该区间的“恶劣度”。

输入输出样例

  • 输入#1

    1
    5 5
    1 2 3 4 5
    2 1 5
    1 1 5
    1 2 5
    1 3 1
    2 1 5

    输出#1

    1
    0

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

首页