出处:https://acs.jxnu.edu.cn/contest/23/board/challenge/E;
重点单词:
Append the MEX of the first k numbers of the array a to the end of array b
将数组a的前k个数的MEX附加到数组b的末尾
the first k numbers 前k个数
Meximum Array
描述:
Mihai has just learned about the MEX concept and since he liked it so much, he decided to use it right away.
Mihai刚刚了解了MEX的概念,因为他非常喜欢它,所以他决定立即使用它。
Given an array a">aa of n">n non-negative integers, Mihai wants to create a new array b">b that is formed in the following way:
a">n">b">给定n个非负整数的数组a,Mihai希望创建一个新的数组b,其形式如下:
While a">a is not empty:
a">当a数组不为空:
- Choose an integer k">k (1≤k≤|a|">1≤k≤|a|1≤k≤|a|).
- Append the MEX of the first k">kk numbers of the array a">aa to the end of array b">bb and erase them from the array a">aa, shifting the positions of the remaining numbers in a">aa.
选择整数k
将数组a的前k个数的MEX附加到数组b的末尾,并将它们从数组a中删除,从而移动a中其余数的位置。
But, since Mihai loves big arrays as much as the MEX concept, he wants the new array b">bb to be the lexicographically maximum. So, Mihai asks you to tell him what the maximum array b">bb that can be created by constructing the array optimally is.
b">b">但是,由于Mihai和MEX概念一样喜欢大数组,他希望新的数组b在词典编纂上是最大的。所以,Mihai让你告诉他,通过优化构建数组可以创建的最大数组b是多少。
An array x">x is lexicographically greater than an array y">yy if in the first position where x">xx and y">yy differ xi>yi">xi>yixi>yi or if |x|>|y|">|x|>|y||x|>|y| and y">yy is a prefix of x">xx (where |x|">|x||x| denotes the size of the array x">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,31,2,3}) =0">=0=0 and MEX({0,1,2,4,5">0,1,2,4,50,1,2,4,5}) =3">=3=3.
如果在第一个位置x和yy不同xi>yixi>yi,或者如果|x |>y | | x |>y |,并且yy是xx的前缀(其中| x | | x |表示数组xx的大小),那么数组xx在词典学上大于数组yy。
一组非负整数的MEX是最小的非负整数,因此它不在该集合中。例如,MEX({1,2,3})=0=0和MEX({0,1,2,4,5)=3。
输入:
The first line of the input contains a single integer t">tt (1≤t≤100">1≤t≤1001≤t≤100) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n">nn (1≤n≤2⋅105">1≤n≤2?1051≤n≤2?105) — the number of elements in the array a">aa.
The second line of each test case contains n">nn non-negative integers a1,…,an">a1,…,ana1,…,an (0≤ai≤n">0≤ai≤n0≤ai≤n), where ai">aiai is the i">ii-th integer from the array a">aa.
It is guaranteed that the sum of n">nn over all test cases does not exceed 2⋅105">2?1052?105.
输出:
For each test case print m">mm — the length of the maximum array b">bb Mihai can create, followed by m">mm integers denoting the elements of the array b">bb.
样例输入:
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
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 b">bb is obtained by selecting k=5">k=5k=5, resulting in the MEX">MEXMEX of the whole array a">aa. It is lexicographically maximum because an array starting with a smaller number than 4">44 is lexicographically smaller, and choosing a k<5">k<5k<5 would result in an array starting with a number smaller than 4">44.
In the second test case, there are two ways to obtain the maximum array: first selecting k=6">k=6k=6, then k=2">k=2k=2, or first selecting k=7">k=7k=7 and then k=1">k=1k=1.