MEX (周练翻译)

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

M学习了关于MEX的感念并且因为喜欢它,他决定立刻使用它

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

While a is not empty:

Choose an integer k (1≤k≤|a|).


Append the MEX of the first k numbers of the array a to the end of array b and erase them from the array a, shifting the positions of the remaining numbers in a.

给一个n个非负元素的数组,M想通过以下方式建立一个新数组b:

当数组非空时 选择一个整数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 to be the lexicographically maximum. So, Mihai asks you to tell him what the maximum array b that can be created by constructing the array optimally is.

但是,因为M和喜欢MEX一样,喜欢大数组,他想这个新数组b的字典序最大。所以M要求你告诉他能从a中创造出来的b的最大数组是什么。



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

当数组x和数组y的第一个不同的位置并且x>y时或者y是x的前缀,x字典序大于y。



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}) =0 and MEX({0,1,2,4,5}) =3.

MEX是一组非负整数中最小的不在这个集合中的整数。



输入:
The first line of the input contains a single integer t (1≤t≤100) — the number of test cases. The description of test cases follows.

第一行输入一个整数t,测试样例的数量。测试用例的描述如下。


The first line of each test case contains a single integer n (1≤n≤2⋅105) — the number of elements in the array a.

每个样例的第一行包含一个整数n 数组a元素的数量。

The second line of each test case contains n non-negative integers a1,…,an (0≤ai≤n), where ai is the i-th integer from the array a.

第二行包含n个非负数

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

保证所有样例的总和不超过2*1e5

输出:
For each test case print m — the length of the maximum array b Mihai can create, followed by m integers denoting the elements of the array b.

对于每一个样例输出一个m   M\能创作的最大数组b的长度。后面是数组b元素

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值