CF2262A1.Floor of MEX (Easy Version)
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
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. ∗
Farmer John chooses a (possibly empty) subset A⊆0,1,…,n−1. He then constructs an array a of length n, where ak=f(A,k) for every 1≤k≤n.
Bessie, being a mischievous cow, hides the set A. Farmer John is left only with the array a1,a2,…,an.
Your task is to construct any (possibly empty) subset B⊆0,1,…,n−1 such that f(B,k)=ak for every 1≤k≤n. Farmer John will only give you arrays where such a B exists.
∗mex(c) denotes the minimum excluded (MEX)∗ of the collection c. (in this case, the minimum non-negative integer not present in the set)
这是该问题的简单版本。两个版本的区别在于,在本版本中,你只需找到一个满足约束条件的子集即可。仅当你解决了该问题的所有版本时,才可进行 Hack。
定义
f(S,x)=mex({⌊xy⌋:y∈S}),
其中 S 是一个非负整数集合,x 是一个正整数。∗
农夫约翰选择一个(可能为空的)子集 A⊆{0,1,…,n−1}。然后他构造一个长度为 n 的数组 a,使得对每个 1≤k≤n,均有 ak=f(A,k)。
调皮的奶牛贝茜藏起了集合 A。农夫约翰手中仅剩下数组 a1,a2,…,an。
你的任务是构造任意一个(可能为空的)子集 B⊆{0,1,…,n−1},使得对每个 1≤k≤n,均有 f(B,k)=ak。农夫约翰只会给出那些确实存在这样的 B 的数组。
∗mex(c) 表示集合 c 的最小未出现值(MEX)∗(即该集合中不包含的最小非负整数)。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤105).
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤n).
You will only be given arrays where there exists B⊆0,1,…,n−1 such that f(B,k)=ak for every 1≤k≤n.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤n)。
你所收到的所有数组均满足:存在集合 B⊆{0,1,…,n−1},使得对每个 1≤k≤n 都有 f(B,k)=ak。
保证所有测试用例的 n 值之和不超过 105。
输出格式
For each test case, output two lines.
On the first line, output an integer m — the size of the set B.
On the second line, output m distinct integers b1,b2,…,bm — the elements of B. If m=0, the second line should be empty.
The elements of B may be printed in any order.
If there are multiple solutions, you may output any of them.
对每个测试用例,输出两行。
第一行输出一个整数 m —— 集合 B 的大小。
第二行输出 m 个互不相同的整数 b1,b2,…,bm —— 集合 B 的元素。若 m=0,则第二行应为空行。
集合 B 的元素可以以任意顺序输出。
若存在多个解,可输出其中任意一个。
输入输出样例
输入#1
3 6 0 3 2 2 2 1 5 2 1 1 1 1 6 1 2 1 1 1 1
输出#1
5 1 2 3 4 5 2 0 1 2 0 2
说明/提示
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].
For the second test case, one possible answer is $$ B=\{0,1\}. $$ Then f(B,1)=2, and for every 2≤k≤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={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]。
对于第二个测试用例,一个可能的答案是 $$ B={0,1}. $$ 此时 f(B,1)=2,而对于每个 2≤k≤5,均有 $$ \left{\left\lfloor y/k\right\rfloor : y\in B\right}={0}, $$ 故 f(B,k)=1。因此所得数组为 [2,1,1,1,1]。
输入解题思路,AI测评打分。不知道怎么写?