#P4263. [Code+#3] 投票统计

[Code+#3] 投票统计

Description

To review the problem-setting work over the past period, Captain Wang organized a "My Favorite Problem" selection and invited all contestants to vote for the problems.

Specifically, each problem has a positive integer as its ID. There are nn contestants voting; each contestant votes for exactly one problem, and the ii-th contestant votes for the problem with ID aia_i.

Since there are many voters, Captain Wang asks you to help tally the votes. You need to find the number of problems that received the most votes and their IDs, and list these IDs in ascending order. However, there is one exception: if all problems that received at least one vote have the same number of votes, then Captain Wang considers the event unsuccessful, and you should output -1.

Input Format

The first line contains a positive integer TT, the number of testdata groups. There is no blank line between groups.

The next 2T2T lines describe each group in order:

Each group contains two lines. The first line contains a positive integer nn, the number of contestants participating. The second line contains nn space-separated positive integers a1ana_1\sim a_n, where the ii-th number aia_i is the ID of the problem voted for by the ii-th contestant.

Output Format

The output consists of TT groups, with no blank lines between groups. For each group:

If the exception described in the statement does not occur, output two lines for this group. On the first line, output a positive integer mm, the number of problems that received the most votes. On the second line, output mm positive integers in ascending order, which are the IDs of these problems.

If the exception occurs, output one line for this group: output -1.

3
10
2 6 1 2 1 1 2 6 7 1
10
10 3 6 6 3 10 6 6 6 2
10
8 8 10 10 10 10 8 5 8 8
1
1
1
6
1
8
3
10
1 4 3 1 8 8 7 2 8 7
10
1 10 9 1 3 2 9 9 2 1
10
4 1 5 4 1 9 5 5 4 1
1
8
2
1 9
3
1 4 5
3
10
3 3 10 8 8 3 10 8 10 3
10
2 2 8 6 8 4 2 4 4 8
10
6 2 5 6 7 5 7 10 2 10
1
3
3
2 4 8
-1

Hint

Test point ID Range of nn Range of aia_i Special notes
1 =2000=2000 n\leq n The problem with the most votes is unique
2 Same as above Same as above Same as above
3 109\leq 10^9
4 n\leq n The exception will not occur
5 Same as above Same as above
6 109\leq 10^9
7 n\leq n None
8 Same as above Same as above
9 109\leq 10^9
10 Same as above
11 =100000=100000 n\leq n The problem with the most votes is unique
12 Same as above Same as above Same as above
13 109\leq 10^9
14 n\leq n The exception will not occur
15 Same as above Same as above
16 109\leq 10^9
17 n\leq n None
18 Same as above Same as above
19 109\leq 10^9
20 Same as above

Credit: https://www.luogu.org/discuss/show?postid=35727.

Translated by ChatGPT 5