第 1120 场 Codeforces Round(Div. 2)
C1
MEX 的下取整(简单版)
Floor of MEX (Easy Version)
Codeforces
未评级
原题
← BC2 →

MEX 的下取整(简单版)AI (CI翻译)

This is the easy version of the problem. The difference between the versions is that in this version, you only need to find one subset that satisfies the constraints. You can hack only if you solved all versions of this problem.

这是本题的简单版本。两个版本的区别在于,在本版本中,你只需要找到一个满足约束条件的子集。仅当你解决了本题的所有版本后,才能进行 hack。AI (CI翻译)

Let $$ f(S,x)=\text{mex}\left(\left\{\left\lfloor \frac{y}{x}\right\rfloor : y\in S\right\}\right), $$ where $S$ is a set of non-negative integers and $x$ is a positive integer. $^{\text{∗}}$

令 $$ f(S,x)=\text{mex}\left(\left\{\left\lfloor \frac{y}{x}\right\rfloor : y\in S\right\}\right), $$ 其中,$S$ 是一个非负整数集合,$x$ 是一个正整数。$^{\text{∗}}$AI (CI翻译)

Farmer John chooses a (possibly empty) subset $A\subseteq \{0,1,\ldots,n-1\}$. He then constructs an array $a$ of length $n$, where $a_k = f(A,k)$ for every $1\le k\le n$.

Farmer John 选择一个(可能为空的)子集 $A\subseteq \{0,1,\ldots,n-1\}$。随后,他构造一个长度为 $n$ 的数组 $a$,其中对于每个 $1\le k\le n$,都有 $a_k = f(A,k)$。AI (CI翻译)

Bessie, being a mischievous cow, hides the set $A$. Farmer John is left only with the array $a_1,a_2,\ldots,a_n$.

调皮的奶牛 Bessie 把集合 $A$ 藏了起来。Farmer John 只剩下数组 $a_1,a_2,\ldots,a_n$。AI (CI翻译)

Your task is to construct any (possibly empty) subset $B\subseteq \{0,1,\ldots,n-1\}$ such that $f(B,k)=a_k$ for every $1 \le k \le n$. Farmer John will only give you arrays where such a $B$ exists.

你的任务是构造任意一个(可能为空的)子集 $B\subseteq \{0,1,\ldots,n-1\}$,使得对于每个 $1 \le k \le n$,都有 $f(B,k)=a_k$。Farmer John 只会给出保证存在这样的 $B$ 的数组。AI (CI翻译)

$^{\text{∗}}$$\operatorname{mex}(c)$ denotes the minimum excluded (MEX)$^{\text{∗}}$ of the collection $c$. (in this case, the minimum non-negative integer not present in the set)

$^{\text{∗}}$$\operatorname{mex}(c)$ 表示集合 $c$ 的最小未出现值(MEX)$^{\text{∗}}$。(在本题中,即集合中不存在的最小非负整数。)AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各个测试用例的描述。AI (CI翻译)

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$).

每个测试用例的第一行包含一个整数 $n$($1 \leq n \leq 10^5$)。AI (CI翻译)

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0 \leq a_i \leq n$).

每个测试用例的第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($0 \leq a_i \leq n$)。AI (CI翻译)

You will only be given arrays where there exists $B \subseteq \{0,1,\ldots,n-1\}$ such that $f(B,k)=a_k$ for every $1 \le k \le n$.

保证对于给出的每个数组,都存在一个 $B \subseteq \{0,1,\ldots,n-1\}$,使得对于每个 $1 \le k \le n$,都有 $f(B,k)=a_k$。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

保证所有测试用例的 $n$ 之和不超过 $10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output two lines.

对于每个测试用例,输出两行。AI (CI翻译)

On the first line, output an integer $m$ — the size of the set $B$.

第一行输出一个整数 $m$,表示集合 $B$ 的大小。AI (CI翻译)

On the second line, output $m$ distinct integers $b_1,b_2,\ldots,b_m$ — the elements of $B$. If $m=0$, the second line should be empty.

第二行输出 $m$ 个互不相同的整数 $b_1,b_2,\ldots,b_m$,表示 $B$ 中的元素。如果 $m=0$,第二行应为空。AI (CI翻译)

The elements of $B$ may be printed in any order.

$B$ 中的元素可以按任意顺序输出。AI (CI翻译)

If there are multiple solutions, you may output any of them.

如果有多个解,你可以输出其中任意一个。AI (CI翻译)

Note

说明

AI (CI翻译)

For the first test case, one possible answer is $$ B=\{1,2,3,4,5\}. $$ Then $$ f(B,1)=\text{mex}(\{1,2,3,4,5\})=0, $$ $$ f(B,2)=\text{mex}(\{0,1,2\})=3, $$ and $$ f(B,3)=f(B,4)=f(B,5)=2. $$ Finally, $$ f(B,6)=\text{mex}(\{0\})=1. $$ Thus the array is $[0,3,2,2,2,1]$.

对于第一个测试用例,一种可能的答案是 $$ B=\{1,2,3,4,5\}. $$ 此时,$$ f(B,1)=\text{mex}(\{1,2,3,4,5\})=0, $$ $$ f(B,2)=\text{mex}(\{0,1,2\})=3, $$ 并且 $$ f(B,3)=f(B,4)=f(B,5)=2. $$ 最后,$$ f(B,6)=\text{mex}(\{0\})=1. $$ 因此,该数组为 $[0,3,2,2,2,1]$。AI (CI翻译)

For the second test case, one possible answer is $$ B=\{0,1\}. $$ Then $f(B,1)=2$, and for every $2\le k\le 5$, we have $$ \left{\left\lfloor y/k\right\rfloor : y\in B\right}={0}, $$ so $f(B,k)=1$. Therefore, the array is $[2,1,1,1,1]$.

对于第二个测试用例,一种可能的答案是 $$ B=\{0,1\}. $$ 此时 $f(B,1)=2$,并且对于每个 $2\le k\le 5$,都有 $$ \left{\left\lfloor y/k\right\rfloor : y\in B\right}={0}, $$ 因此 $f(B,k)=1$。所以,该数组为 $[2,1,1,1,1]$。AI (CI翻译)

样例

Input #1
3
6
0 3 2 2 2 1
5
2 1 1 1 1
6
1 2 1 1 1 1
Output #1
5
1 2 3 4 5
2
0 1
2
0 2
InputCopy OutputCopy
题目信息
题号
2263C1
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。