#abc329d. D - Election Quick Report

D - Election Quick Report

Score : 350350 points

问题描述

存在一场选举,从编号为 1,2,,N1, 2, \ldots, NNN 名候选人中选出一名获胜者,目前已经投出了 MM 票。

每张选票都恰好投给了一名候选人,其中第 ii 张选票投给了候选人 AiA_i

投票将按照从第一票到最后一票的顺序进行计数,并且在每次计票后,都会更新并显示当前的获胜者。

在已统计的所有选票中,获得最多票数的候选人即为获胜者。如果有多个候选人得票最多,则编号最小的候选人为获胜者。

对于每个 i=1,2,,Mi = 1, 2, \ldots, M,请确定仅计算前 ii 张选票时的获胜者。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is an election to choose one winner from NN candidates with candidate numbers 1,2,,N1, 2, \ldots, N, and there have been MM votes cast.

Each vote is for exactly one candidate, with the ii-th vote being for candidate AiA_i.

The votes will be counted in order from first to last, and after each vote is counted, the current winner will be updated and displayed.

The candidate with the most votes among those counted is the winner. If there are multiple candidates with the most votes, the one with the smallest candidate number is the winner.

For each i=1,2,,Mi = 1, 2, \ldots, M, determine the winner when counting only the first ii votes.

Constraints

  • 1N,M2000001 \leq N, M \leq 200000
  • 1AiN1 \leq A_i \leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \ldots AMA_M

Output

Print MM lines.

The ii-th line should contain the winner's candidate number when counting only the first ii votes.

Sample Input 1

3 7
1 2 2 3 1 3 3

Sample Output 1

1
1
2
2
1
1
3

Let CiC_i denote the number of votes for candidate ii.

  • After the first vote is counted, (C1,C2,C3)=(1,0,0)(C_1, C_2, C_3) = (1, 0, 0), so the winner is 11.
  • After the second vote is counted, (C1,C2,C3)=(1,1,0)(C_1, C_2, C_3) = (1, 1, 0), so the winner is 11.
  • After the third vote is counted, (C1,C2,C3)=(1,2,0)(C_1, C_2, C_3) = (1, 2, 0), so the winner is 22.
  • After the fourth vote is counted, (C1,C2,C3)=(1,2,1)(C_1, C_2, C_3) = (1, 2, 1), so the winner is 22.
  • After the fifth vote is counted, (C1,C2,C3)=(2,2,1)(C_1, C_2, C_3) = (2, 2, 1), so the winner is 11.
  • After the sixth vote is counted, (C1,C2,C3)=(2,2,2)(C_1, C_2, C_3) = (2, 2, 2), so the winner is 11.
  • After the seventh vote is counted, (C1,C2,C3)=(2,2,3)(C_1, C_2, C_3) = (2, 2, 3), so the winner is 33.

Sample Input 2

100 5
100 90 80 70 60

Sample Output 2

100
90
80
70
60

Sample Input 3

9 8
8 8 2 2 8 8 2 2

Sample Output 3

8
8
8
2
8
8
8
2

update @ 2024/3/10 01:54:15