【无标题】

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 (1≤k≤|a|1≤k≤|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>yixi>yi 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,31,2,3}) =0=0 and MEX({0,1,2,4,50,1,2,4,5}) =3=3.

输入:

The first line of the input contains a single integer tt (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 nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in the array aa.

The second line of each test case contains nn non-negative integers a1,…,ana1,…,an (0≤ai≤n0≤ai≤n), where aiai is the ii-th integer from the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

输出:

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.

样例输入:

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 bb is obtained by selecting k=5k=5, resulting in the MEX of the whole array aa. It is lexicographically maximum because an array starting with a smaller number than 4 is lexicographically smaller, and choosing a k<5k<5 would result in an array starting with a number smaller than 4.

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.

翻译

Mihai刚刚了解了MEX的概念,因为他非常喜欢它,所以他决定立即使用它。
给定一个由n个非负整数组成的数组a,Mihai希望创建一个新的数组b,其形式如下:
虽然a不是空的:
选择一个整数k(1)≤K≤|a |)。
将数组a的前k个数字的MEX附加到数组b的末尾,并将它们从数组a中删除,从而移动a中其余数字的位置。
但是,由于Mihai和MEX概念一样喜欢大数组,他希望新的数组b在词典编纂上是最大的。所以,Mihai让你告诉他,通过优化构建数组,可以创建的最大数组b是多少。
如果在第一个位置x和y不同xi>yi,或者如果| x |>y |且y是x的前缀(其中| x |表示数组x的大小),则数组x在词典上大于数组y。
一组非负整数的MEX是最小的非负整数,因此它不在该集合中。例如,MEX({1,2,3})=0和MEX({0,1,2,4,5})=3。
输入:
输入的第一行包含一个整数t(1≤T≤100)-测试用例的数量。测试用例的描述如下。
每个测试用例的第一行包含一个整数n(1)≤N≤2.⋅105)-数组a中的元素数。
每个测试用例的第二行包含n个非负整数a1,…,an(0≤ai≤n) ,其中ai是数组a中的第i个整数。
保证所有测试用例中n的总和不超过2⋅105
输出:
对于每个测试用例print m——Mihai可以创建的最大数组b的长度,后面是表示数组b元素的m个整数。
样例输入:
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 
复制
注释:
在第一个测试用例中,通过选择k=5获得字典最大数组b,从而得到整个数组a的MEX。它是字典最大值,因为以小于4的数字开头的数组在字典上更小,而选择k<5将导致以小于4的数字开头的数组。
在第二个测试用例中,有两种方法可以获得最大数组:首先选择k=6,然后选择k=2,或者首先选择k=7,然后选择k=1。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值