CF2184G.Nastiness of Segments
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Andrey remembered that he has n blocks numbered from 1 to n. On the block with number i, there is initially an integer ai written. He arranged them in a row in increasing order of their numbers: first is the block with number 1, then the block with number 2, and so on, with the block with number n at the end.
For a certain segment of consecutive blocks [l,r] (1≤l≤r≤n), we call an integer d (0≤d≤r−l) nasty if min(al,al+1,…,al+d)=d.
Andrey is very curious, so he wants to perform q operations of one of two types:
- Change the number ai written on the i-th block to x.
- Determine the nastiness of the segment [l, r] (1≤l≤r≤n). The nastiness of the segment refers to the number of nasty numbers d (0≤d≤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!
安德烈记得自己有 n 个编号从 1 到 n 的方块。在编号为 i 的方块上,初始时写有一个整数 ai。他将这些方块按编号升序排成一行:最前面是编号为 1 的方块,接着是编号为 2 的方块,依此类推,最后是编号为 n 的方块。
对于某个连续的方块区间 [l,r](其中 1≤l≤r≤n),若整数 d(满足 0≤d≤r−l)使得
min(al,al+1,…,al+d)=d,
则称 d 是“讨厌的”(nasty)。
安德烈非常好奇,因此他希望执行 q 次操作,每次操作为以下两种类型之一:
- 将第 i 个方块上的数 ai 修改为 x;
- 查询区间 [l, r](其中 1≤l≤r≤n)的“讨厌度”(nastiness)。该区间讨厌度定义为:满足上述条件的讨厌整数 d(0≤d≤r−l)的个数。
安德烈无法快速处理这些查询,于是向你求助。请帮助他完成上述操作!
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n and q (1≤n,q≤2⋅105) — the number of blocks and the number of operations, respectively.
The next line contains n integers a1,a2,…,an (1≤ai≤2⋅105) — the initial numbers written on the blocks.
The following q lines describe the operations to be performed.
Each line starts with an integer idx (1≤idx≤2) — the type of operation.
If idx=1, then two integers i (1≤i≤n) and x (1≤x≤2⋅105) follow — the description of the first type of operation.
If idx=2, then two integers l and r (1≤l≤r≤n) follow — the description of the second type of operation.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105, and the sum of q over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤2⋅105)—— 分别表示方块的数量和操作的数量。
下一行包含 n 个整数 a1,a2,…,an(1≤ai≤2⋅105)—— 表示方块上初始写下的数字。
接下来的 q 行描述将要执行的操作。
每行以一个整数 idx(1≤idx≤2)开头—— 表示操作类型。
若 idx=1,则随后是两个整数 i(1≤i≤n)和 x(1≤x≤2⋅105)—— 描述第一类操作。
若 idx=2,则随后是两个整数 l 和 r(1≤l≤r≤n)—— 描述第二类操作。
保证所有测试用例中 n 的总和不超过 2⋅105,且所有测试用例中 q 的总和不超过 2⋅105。
输出格式
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测评打分。不知道怎么写?