CF1270H.Number of Components
NOI/NOI+/CTSC
通过率:0%
时间限制:8.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Suppose that we have an array of n distinct numbers a1,a2,…,an. Let's build a graph on n vertices as follows: for every pair of vertices i<j let's connect i and j with an edge, if ai<aj. 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] is 1, weight of array [5,4,3] is 3.
You have to perform q 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).
假设我们有一个包含 n 个互不相同数字的数组 a1,a2,…,an。我们据此在 n 个顶点上构造一张图:对每一对满足 i<j 的顶点 i 和 j,若 ai<aj,则在 i 和 j 之间连一条边。我们将该数组的权值定义为这张图中连通块的个数。例如,数组 [1,4,2] 的权值为 1,数组 [5,4,3] 的权值为 3。
你需要执行 q 次如下形式的查询:修改数组中某位置上的值。每次操作后,请输出当前数组的权值。这些更新操作不是相互独立的(即每次修改会持续影响后续操作)。
输入格式
The first line contains two integers n and q (1≤n,q≤5⋅105) — the size of the array and the number of queries.
The second line contains n integers a1,a2,…,an (1≤ai≤106) — the initial array.
Each of the next q lines contains two integers pos and x (1≤pos≤n, 1≤x≤106,x=apos). It means that you have to make apos=x.
It's guaranteed that at every moment of time, all elements of the array are different.
第一行包含两个整数 n 和 q(1≤n,q≤5⋅105)—— 分别表示数组的大小和查询次数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤106)—— 表示初始数组。
接下来的 q 行中,每行包含两个整数 pos 和 x(1≤pos≤n, 1≤x≤106, x=apos)。这表示你需要将 apos 修改为 x。
保证在任意时刻,数组中的所有元素互不相同。
输出格式
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], the weight is equal to 3.
After the second query array looks like [25,40,45,20,10], the weight is still equal to 3.
After the third query array looks like [48,40,45,20,10], the weight is equal to 4.
第一次查询后,数组变为 [25,40,30,20,10],其权重等于 3。
第二次查询后,数组变为 [25,40,45,20,10],其权重仍等于 3。
第三次查询后,数组变为 [48,40,45,20,10],其权重等于 4。
输入解题思路,AI测评打分。不知道怎么写?