QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 1024 MB 總分: 100

#4835. 众数

统计

给定一个长度为 $n$ 的数组 $a$。定义 $cnt_x$ 为 $x$ 在 $a$ 中出现的次数。

现在你可以进行至多一次以下操作:选择一个非空子数组 $a_l, a_{l+1}, a_{l+2}, \dots, a_r$ 和一个整数 $k \in [-10^9, 10^9]$,并将 $k$ 加到该子数组的所有元素上。

你的第一个任务是求出操作后 $W = \max\{cnt_x \mid x \in \mathbb{Z}\}$ 的最大可能值。 你的第二个任务是找出所有在操作后能达到 $cnt_v = W$ 的整数 $v$。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 20$),表示测试用例的数量。

每个测试用例包含两行。第一行包含一个整数 $n$ ($2 \le n \le 2 \cdot 10^5$),第二行包含 $n$ 个整数,表示数组 $a$ ($1 \le a_i \le 10^9$)。

保证 $\sum n \le 5 \cdot 10^5$,且 $a_i$ 不全相同。

输出格式

对于每个测试用例,第一行输出一个整数,表示最大值 $W$。随后按升序输出所有满足条件的整数 $v$。

样例

样例输入 1

4
5
1 2 3 2 1
5
1 1 3 1 1
6
2 4 2 4 8 8
5
1 2 3 4 5

样例输出 1

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

说明

各测试用例的 $W$ 值分别为 4, 5, 4, 2。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.