#P8330. [ZJOI2022] 众数

    ID: 9393 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>各省省选2022浙江O2优化分块根号分治

[ZJOI2022] 众数

Problem Description

Kurenai Kujou is a pitiful girl with superpowers, but her superpower can only be used on some strange things.

One day, Kurenai got a sequence a1,a2,,ana_1, a_2, \ldots, a_n. She can use her superpower on this sequence once: choose an interval [l,r][l, r] (1lrn1 \le l \le r \le n) and an integer k[109,109]k \in [-{10}^9, {10}^9], and add kk to all numbers al,al+1,,ara_l, a_{l + 1}, \ldots, a_r in the interval.

Kurenai likes sequences that look as consistent as possible, so she wants the final sequence to have the mode occur as many times as possible. Given the sequence aa, you need to output the maximum possible number of occurrences of the mode in the final sequence, and output all possible values of this mode. Note that for a sequence, the mode may have more than one value.

Input Format

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

For each test case, the first line contains the sequence length nn, and the second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n.

Output Format

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

Suppose this mode has kk different possible values. Then output these values in increasing order, one per line, for a total of kk lines.

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

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

见附件中的 mode/mode_ex2.in
见附件中的 mode/mode_ex2.ans

Hint

For all testdata: 1T201 \le T \le 20, 2n2×1052 \le n \le 2 \times {10}^5, 1ai1091 \le a_i \le {10}^9, it is guaranteed that n5×105\sum n \le 5 \times {10}^5, and the aia_i are not all equal.

The specific limits for each test point are shown in the table below:

Test Point ID n\sum n \le nn \le Special Constraint
141 \sim 4 30003000 300300 None
585 \sim 8 5×1055 \times {10}^5 2×1052 \times {10}^5 aia_i has only 55 distinct values
9109 \sim 10 2×1052 \times {10}^5 5000050000 None
112011 \sim 20 5×1055 \times {10}^5 2×1052 \times {10}^5

Translated by ChatGPT 5