#727
Unrated
Election Queries
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: The time limit for this problem is 3s, 1.5x the default.

Farmer John has NN (2N21052 \leq N \leq 2 \cdot 10^5) cows numbered from 11 to NN. An election is being held in FJ's farm to determine the two new head cows in his farm. Initially, it is known that cow ii will vote for cow aia_i (1aiN1 \leq a_i \leq N).

To determine the two head cows, FJ will hold his election in the following process:

Choose an arbitrary subset SS of his cows that contains at least one cow but not all cows. FJ is able to choose cow xx as the first head cow if its votes appear most frequently among all votes cast by cows in SS. FJ is able to choose cow yy as the second head cow if its votes appear most frequently among votes cast by cows not in SS.

For a fixed subset SS, FJ denotes the diversity between his head cows as xy|x - y|. As FJ does not like having leaders with similar numbers, he wants to choose SS such that the diversity is maximized. Note that if FJ is not able to choose two distinct head cows, then the diversity is 00.

However, some cows keep changing their minds, and FJ may have to rerun the election many times! Therefore, he asks you QQ (1Q1051 \leq Q \leq 10^5) queries. In each query, a cow changes their vote. After each query, he asks you for the maximum possible diversity among his new head cows.

입력

The first line contains NN and QQ.

The following line contains a1,a2,,aNa_1, a_2, \ldots, a_N.

The following QQ lines contain two integers ii and xx, representing the update ai=xa_i = x (1i,xN1 \leq i, x \leq N).

출력

Output QQ lines, the ii'th of which is the maximum possible diversity after the first ii queries.

예제 입력 1

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

예제 출력 1

4
3
2

예제 입력 2

8 5
8 1 4 2 5 4 2 3
7 4
8 4
4 1
5 8
8 4

예제 출력 2

4
4
4
7
7

점수

Inputs 3-4: N,Q100N, Q \leq 100Inputs 5-7: N,Q3000N, Q \leq 3000Inputs 8-15: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.