CF1270H.Number of Components

普及/提高-

通过率:0%

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 < j let's connect ii and jj with an edge, if ai<aja_i < 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).

输入格式

The first line contains two integers nn and qq ( 1n,q51051 \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 ( 1ai1061 \le a_i \le 10^6 ) — the initial array.

Each of the next qq lines contains two integers pospos and xx ( 1posn1 \le pos \le n , 1x106,xapos1 \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.

输出格式

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 .

首页