QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show] Hackable ✓

#4008. Mode

Statistics

Kujou Karen is a girl with superpowers, but her powers can only be used for some strange things.

One day, Karen obtained a sequence $a_1, a_2, \dots, a_n$. She can use her superpower once on this sequence: choose an interval $[l, r]$ ($1 \le l \le r \le n$) and an integer $k \in [-10^9, 10^9]$, and add $k$ to all numbers $a_l, a_{l+1}, \dots, a_r$ in the interval.

Kujou Karen likes sequences that are relatively consistent, so she wants the frequency of the mode in the final sequence to be as large as possible. Given the sequence $a$, you need to output the maximum possible frequency of the mode in the final sequence, and all possible values of this mode. Note that for a sequence, there may be more than one value that is a mode.

Input

The input contains multiple test cases. The first line contains the number of test cases $T$.

For each test case, the first line contains the sequence length $n$, and the second line contains $n$ integers $a_1, a_2, \dots, a_n$.

Output

For each test case, output the maximum frequency of the mode in the final sequence on the first line.

Suppose there are $k$ different possible values for this mode. Output these values in increasing order on the next $k$ lines.

Constraints

For all test cases: $1 \le T \le 20$, $2 \le n \le 200\,000$, $1 \le a_i \le 10^9$. It is guaranteed that $\sum n \le 500\,000$ and that not all $a_i$ are equal.

The specific constraints for each test case are as follows:

Test Case ID $\sum n \le$ $n \le$ Special Constraints
$1 \sim 4$ $3\,000$ $300$ None
$5 \sim 8$ $500\,000$ $200\,000$ $a_i$ only takes $5$ distinct values
$9 \sim 10$ $200\,000$ $50\,000$ None
$11 \sim 20$ $500\,000$ $200\,000$ None

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.