Logo
(追記) (追記ここまで)

33764번 - Election Queries 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB74211724.638%

문제

Farmer John has $N$ (2ドル \leq N \leq 2 \cdot 10^5$) cows numbered from 1ドル$ to $N$. 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 $i$ will vote for cow $a_i$ (1ドル \leq a_i \leq N$).

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

  • Choose an arbitrary subset $S$ of his cows that contains at least one cow but not all cows. FJ is able to choose cow $x$ as the first head cow if its votes appear most frequently among all votes cast by cows in $S$.
  • FJ is able to choose cow $y$ as the second head cow if its votes appear most frequently among votes cast by cows not in $S$.
  • For a fixed subset $S,ドル FJ denotes the diversity between his head cows as $|x - y|$. As FJ does not like having leaders with similar numbers, he wants to choose $S$ such that the diversity is maximized. Note that if FJ is not able to choose two distinct head cows, then the diversity is 0ドル$.

However, some cows keep changing their minds, and FJ may have to rerun the election many times! Therefore, he asks you $Q$ (1ドル \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 $N$ and $Q$.

The following line contains $a_1, a_2, \ldots, a_N$.

The following $Q$ lines contain two integers $i$ and $x,ドル representing the update $a_i = x$ (1ドル \leq i, x \leq N$).

출력

Output $Q$ lines, the $i$'th of which is the maximum possible diversity after the first $i$ queries.

제한

예제 입력 1

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

예제 출력 1

4
3
2

After the first query, $a = [1, 2, 4, 4, 5]$. At the first step of the election, FJ can make $S = \{1, 3\}$. Here, cow 1ドル$ receives one vote and cow 4ドル$ receives one vote. Therefore, FJ can choose either cow 1ドル$ or cow 4ドル$ as its first head cow.

For all cows not in the election, cow 2ドル$ receives one vote, cow 4ドル$ receives one vote, and cow 5ドル$ also receives one vote. Therefore, FJ can choose any one of cows 2ドル,ドル 4ドル,ドル or 5ドル$ to be its second head cow.

To obtain the maximum diversity, FJ can choose cow 1ドル$ as the first head cow and cow 5ドル$ as the second head cow. Therefore, the diversity is $|1-5| = 4$.

After the second query, $a=[2,2,4,4,5]$ and FJ can make $S = \{4, 5\}$. Then, he can choose 5ドル$ as the first head cow and cow 2ドル$ as the second head cow. The maximum possible diversity is $|5 - 2| = 3$.

예제 입력 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

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 US Open Contest > Gold 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /