Election Queries
시간 제한3초메모리 제한2048 MB
투표가 갱신될 때마다, 진 부분집합 S에서 최빈 득표자 x를, 여집합에서 최빈 득표자 y를 골라 |x - y|를 최대로 만드는 값을 구한다.
문제
Farmer John has () cows numbered from to . 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 will vote for cow ().
To determine the two head cows, FJ will hold his election in the following process:
- Choose an arbitrary subset of his cows that contains at least one cow but not all cows. FJ is able to choose cow as the first head cow if its votes appear most frequently among all votes cast by cows in .
- FJ is able to choose cow as the second head cow if its votes appear most frequently among votes cast by cows not in .
- For a fixed subset , FJ denotes the diversity between his head cows as . As FJ does not like having leaders with similar numbers, he wants to choose such that the diversity is maximized. Note that if FJ is not able to choose two distinct head cows, then the diversity is .
However, some cows keep changing their minds, and FJ may have to rerun the election many times! Therefore, he asks you () 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 and .
The following line contains .
The following lines contain two integers and , representing the update ().
출력
Output lines, the 'th of which is the maximum possible diversity after the first queries.