QOJ.ac

QOJ

実行時間制限: 7.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17413. 最大差值

統計

对于一个数组 $B$,定义其得分(记为 $\text{score}(B)$)如下:

初始时有一个变量 $X = 0$。

在一次操作中,选择当前数组 $B$ 的一个非空子序列 $S$。然后:

  • 更新 $X \leftarrow \max(X, \max(S) - \min(S))$;
  • 将 $S$ 中的元素按非降序(从小到大)排序;
  • 将排序后的元素写回 $B$ 中原来选择的位置。

你可以进行任意次数的操作。

$\text{score}(B)$ 的值定义为:在进行某种操作序列后,使得整个数组 $B$ 变为非降序的,变量 $X$ 的最小可能最终值。

给你一个长度为 $N$ 的数组 $A$。

同时给你 $M$ 次修改。每次修改给出两个整数 $P$ 和 $Y$,你必须将 $A_P$ 设为 $Y$。修改是持久的(即会影响后续的修改)。

在每次修改后,输出当前数组的 $\text{score}(A)$。

† 如果序列 $S$ 可以通过从序列 $C$ 中删除若干个(可以是零个或全部)任意位置的元素来获得,则称 $S$ 是 $C$ 的子序列。

输入格式

输入按以下格式给出:

T
N M
A1 A2 ... AN
P1 Y1
...
PM YM

(上述结构会在每个测试用例中重复 $T$ 次)

数据范围

  • 所有输入值均为整数。
  • $1 \le T \le 10^4$
  • $1 \le N, M \le 5 \times 10^5$
  • $1 \le A_i \le N$
  • $1 \le P_i \le N$
  • $1 \le Y_i \le N$
  • 保证所有测试用例中 $N$ 的总和不超过 $5 \times 10^5$。
  • 保证所有测试用例中 $M$ 的总和不超过 $5 \times 10^5$。

输出格式

对于每个测试用例,在每次修改后,在单独的一行中输出一个整数——应用该修改后 $\text{score}(A)$ 的值。

样例

输入样例 1

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

输出样例 1

3
0
2
1
1

说明

测试用例 1:在第一次修改后,数组变为 $[4, 4, 1, 4]$,答案为 $3$。

在同一个测试用例中,在第二次修改后,数组变为 $[4, 4, 4, 4]$,它已经是有序的,因此答案为 $0$。

测试用例 2:在唯一的一次修改后,数组变为 $[2, 1, 5, 4, 4, 5]$,答案为 $1$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.