CF1628A.Meximum Array

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mihai has just learned about the MEX concept and since he liked it so much, he decided to use it right away.

Given an array aa of nn non-negative integers, Mihai wants to create a new array bb that is formed in the following way:

While aa is not empty:

  • Choose an integer kk ( 1ka1 \leq k \leq |a| ).
  • Append the MEX of the first kk numbers of the array aa to the end of array bb and erase them from the array aa , shifting the positions of the remaining numbers in aa .

But, since Mihai loves big arrays as much as the MEX concept, he wants the new array bb to be the lexicographically maximum. So, Mihai asks you to tell him what the maximum array bb that can be created by constructing the array optimally is.

An array xx is lexicographically greater than an array yy if in the first position where xx and yy differ xi>yix_i > y_i or if x>y|x| > |y| and yy is a prefix of xx (where x|x| denotes the size of the array xx ).

The MEX of a set of non-negative integers is the minimal non-negative integer such that it is not in the set. For example, MEX({ 1,2,3{1, 2, 3} }) =0= 0 and MEX({ 0,1,2,4,5{0, 1, 2, 4, 5} }) =3= 3 .

输入格式

The first line of the input contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn ( 1n21051 \leq n \leq 2 \cdot 10^5 ) — the number of elements in the array aa .

The second line of each test case contains nn non-negative integers a1,,ana_1, \ldots, a_n ( 0ain0 \leq a_i \leq n ), where aia_i is the ii -th integer from the array aa .

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case print mm — the length of the maximum array bb Mihai can create, followed by mm integers denoting the elements of the array bb .

输入输出样例

  • 输入#1

    6
    5
    1 0 2 0 3
    8
    2 2 3 4 0 1 2 0
    1
    1
    5
    0 1 2 3 4
    4
    0 1 1 0
    10
    0 0 2 1 1 1 0 0 1 1

    输出#1

    1
    4 
    2
    5 1 
    1
    0 
    1
    5 
    2
    2 2 
    4
    3 2 2 0

说明/提示

In the first test case, the lexicographically maximum array bb is obtained by selecting k=5k=5 , resulting in the MEXMEX of the whole array aa . It is lexicographically maximum because an array starting with a smaller number than 44 is lexicographically smaller, and choosing a k<5k<5 would result in an array starting with a number smaller than 44 .

In the second test case, there are two ways to obtain the maximum array: first selecting k=6k=6 , then k=2k=2 , or first selecting k=7k=7 and then k=1k=1 .

首页