CF2262A2.Floor of MEX (Hard Version)
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the hard version of the problem. The difference between the versions is that in this version, you need to count how many sets satisfy 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 count how many sets (including the empty set) B⊆0,1,…,n−1 such that f(B,k)=ak for every 1≤k≤n. Since the number can be very large, output it modulo 109+7. 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。
你的任务是:计算满足对每个 1≤k≤n 均有 f(B,k)=ak 的集合(包括空集)B⊆{0,1,…,n−1} 的个数。由于答案可能非常大,请输出其对 109+7 取模的结果。农夫约翰只会给你那些确实存在满足条件的 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 testcase, output one number, the number of sets B that satisfy the constraints modulo 109+7.
对于每个测试用例,输出一个数字,即满足约束条件的集合 B 的数量对 109+7 取模的结果。
输入输出样例
输入#1
3 6 0 3 2 2 2 1 5 2 1 1 1 1 6 1 2 1 1 1 1
输出#1
6 1 1
说明/提示
For the first testcase, the 6 subsets are $$\{1, 2, 5\}, \{1, 3, 5\}, \{1, 2, 3, 5\}, \{1, 2, 4, 5\}, \{1, 3, 4, 5\}, \{1, 2, 3, 4, 5\}.$$
For the second testcase, the only subset that satisfies f(B,k)=ak for every 1≤k≤n is 0,1.
对于第一个测试用例,这 6 个子集为
{1,2,5},{1,3,5},{1,2,3,5},{1,2,4,5},{1,3,4,5},{1,2,3,4,5}.
对于第二个测试用例,唯一满足对每个 1≤k≤n 都有 f(B,k)=ak 的子集是 {0,1}。
输入解题思路,AI测评打分。不知道怎么写?