#P15868. 【MX-X26-T4】「Cfz Round 7」breakfast

【MX-X26-T4】「Cfz Round 7」breakfast

Background

An unending dream, an unbearable reality.
They will both eventually turn into ordinary scenery.

Problem Description

Yuki has a sequence aa of length nn.

For the sequence aa, Yuki defines its "Yuyu value" as:

$$\sum_{i=1}^n \operatorname{mex}(\{a_1,\dots,a_i\})$$

That is, the sum of mex⁡\operatorname{mex} over all non-empty prefixes of aa.

Yuki defines one "bigger" operation as:

  • Choose a positive integer ii not greater than nn and a non-negative integer vv, and change the value of aia_i to ai+va_i+v.

For each non-negative integer kk not greater than nn, you need to find: if Yuki performs exactly kk "bigger" operations, what is the maximum possible "Yuyu value" of the sequence aa.

In this problem, the mex⁡\operatorname{mex} of a sequence is the smallest non-negative integer that does not appear in the sequence. For example:

  • mex⁡({1,2,3})=0\operatorname{mex}(\{1,2,3\})=0;
  • mex⁡({0})=1\operatorname{mex}(\{0\})=1;
  • mex⁡({1,0,2,4})=3\operatorname{mex}(\{1,0,2,4\})=3;

In particular, when the sequence is empty, its mex⁡\operatorname{mex} is 00.

Input Format

This problem contains multiple test cases.

The first line contains two integers c,tc,t, representing the subtask ID of this test point and the number of test cases. The sample satisfies c=0c=0.

Then each test case is given as follows:

  • The first line contains an integer nn.
  • The second line contains nn integers a1,…,ana_1,\dots,a_n.

Output Format

For each test case, output one line containing n+1n+1 integers. The (k+1)(k+1)-th integer means the maximum "Yuyu value" that the sequence aa can achieve if Yuki performs exactly kk "bigger" operations.

0 3
4
2 0 0 9
5
0 1 0 2 4
7
4 0 9 8 1 3 8
3 7 7 7 7
11 14 15 15 15 15
9 9 9 9 9 9 9 9

Hint

Sample 1 Explanation

For the 11-st test case:

  • When k=0k=0, the "Yuyu value" of the sequence aa is 0+1+1+1=30+1+1+1=3.
  • When k=1k=1, you can change a3a_3 to 11. Then the "Yuyu value" is 0+1+3+3=70+1+3+3=7.

For the 22-nd test case:

  • When k=0k=0, the "Yuyu value" of the sequence aa is 1+2+2+3+3=111+2+2+3+3=11.
  • When k=1k=1, you can change a3a_3 to 33. Then the "Yuyu value" is 1+2+2+4+5=141+2+2+4+5=14.
  • When k=2k=2, you can change a3a_3 and a4a_4 to 22 and 33 respectively. Then the "Yuyu value" is 1+2+3+4+5=151+2+3+4+5=15.

Constraints

Let ∑n\sum n be the sum of nn within a single test point, and ∑n3\sum n^3 be the sum of n3n^3 within a single test point.

For all testdata:

  • 1≤t≤1051 \le t \le 10^5;
  • 1≤n≤5001 \le n \le 500, ∑n3≤5003\sum n^3 \le 500^3;
  • For all 1≤i≤n1\le i \le n, 0≤ai≤1090 \le a_i \le 10^9.

This problem uses bundled evaluation.

  • Subtask 1 (13 points): n≤5n \le 5, ∑n≤20\sum n \le 20.
  • Subtask 2 (17 points): n≤16n \le 16, ∑n≤20\sum n \le 20.
  • Subtask 3 (27 points): n≤100n \le 100, ∑n3≤1003\sum n^3 \le 100^3.
  • Subtask 4 (7 points): The sequence aa is a permutation of 00 to n−1n-1.
  • Subtask 5 (15 points): The sequence aa is non-decreasing.
  • Subtask 6 (21 points): No special constraints.

Translated by ChatGPT 5