CF1270H.Number of Components

NOI/NOI+/CTSC

通过率:0%

时间限制:8.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Suppose that we have an array of nn distinct numbers a1,a2,…,ana_1, a_2, \dots, a_n. Let's build a graph on nn vertices as follows: for every pair of vertices i<ji \lt j let's connect ii and jj with an edge, if ai<aja_i \lt a_j. Let's define weight of the array to be the number of connected components in this graph. For example, weight of array [1,4,2][1, 4, 2] is 11, weight of array [5,4,3][5, 4, 3] is 33.

You have to perform qq queries of the following form — change the value at some position of the array. After each operation, output the weight of the array. Updates are not independent (the change stays for the future).

假设我们有一个包含 nn 个互不相同数字的数组 a1,a2,…,ana_1, a_2, \dots, a_n。我们据此在 nn 个顶点上构造一张图:对每一对满足 i<ji \lt j 的顶点 ii 和 jj,若 ai<aja_i \lt a_j,则在 ii 和 jj 之间连一条边。我们将该数组的权值定义为这张图中连通块的个数。例如,数组 [1,4,2][1, 4, 2] 的权值为 11,数组 [5,4,3][5, 4, 3] 的权值为 33。

你需要执行 qq 次如下形式的查询:修改数组中某位置上的值。每次操作后,请输出当前数组的权值。这些更新操作不是相互独立的(即每次修改会持续影响后续操作)。

输入格式

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

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1061 \le a_i \le 10^6) — the initial array.

Each of the next qq lines contains two integers pospos and xx (1≤pos≤n1 \le pos \le n, 1≤x≤106,x≠apos1 \le x \le 10^6, x \ne a_{pos}). It means that you have to make apos=xa_{pos}=x.

It's guaranteed that at every moment of time, all elements of the array are different.

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

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \le a_i \le 10^6)—— 表示初始数组。

接下来的 qq 行中,每行包含两个整数 pospos 和 xx(1≤pos≤n1 \le pos \le n, 1≤x≤1061 \le x \le 10^6, x≠aposx \ne a_{pos})。这表示你需要将 aposa_{pos} 修改为 xx。

保证在任意时刻,数组中的所有元素互不相同。

输出格式

After each query, output the weight of the array.

每次查询后,输出数组的权重。

输入输出样例

  • 输入#1

    5 3
    50 40 30 20 10
    1 25
    3 45
    1 48

    输出#1

    3
    3
    4

说明/提示

After the first query array looks like [25,40,30,20,10][25, 40, 30, 20, 10], the weight is equal to 33.

After the second query array looks like [25,40,45,20,10][25, 40, 45, 20, 10], the weight is still equal to 33.

After the third query array looks like [48,40,45,20,10][48, 40, 45, 20, 10], the weight is equal to 44.

第一次查询后,数组变为 [25,40,30,20,10][25, 40, 30, 20, 10],其权重等于 33。

第二次查询后,数组变为 [25,40,45,20,10][25, 40, 45, 20, 10],其权重仍等于 33。

第三次查询后,数组变为 [48,40,45,20,10][48, 40, 45, 20, 10],其权重等于 44。

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

首页