CF2207E2.N-MEX (Counting Version)
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Builder Base Attack (Stage 2) — Supercell, Clash of Clans
This is the counting version of the problem. The difference between the versions is that in this version, you need to count the number of constructions where 0≤bi≤n. You can hack only if you solved all versions of this problem.
The Master Builder doesn't like repetitive tasks — repairing the base, upgrading the town hall fifteen times, and doing yet more programming problems about MEX. So, this is not going to be your ordinary MEX problem.
For any positive integer k, define the k-mex of a collection of integers S to be the k-th smallest nonnegative integer not present in S. For instance, the 1-mex and 2-mex of [1,2,1] are 0 and 3, respectively.
Let n be a positive integer, and consider an array of nonnegative integers [a1,…,an]. Compute the number of arrays of nonnegative integers [b1,…,bn] such that:
- For all 1≤i≤n, the (n−i+1)-mex of [b1,…,bi] is ai.
- Additionally, for all 1≤i≤n, 0≤bi≤n.
Since the number of such arrays may be large, output the answer modulo 109+7.
建筑大师基地进攻(第二阶段)——Supercell,《部落冲突》
本题为计数版本。与其它版本的区别在于:在本版本中,你需要统计满足 0≤bi≤n 的构造方案总数。仅当你已解决本题的所有版本后,才可进行 Hack。
建筑大师讨厌重复性工作——修缮基地、将城镇大厅升级十五次、以及再做一道关于 MEX 的编程题。因此,本题将不是你所熟悉的普通 MEX 问题。
对任意正整数 k,定义整数集合 S 的 k-mex 为 S 中未出现的第 k 小的非负整数。例如,数组 [1,2,1] 的 1-mex 和 2-mex 分别为 0 和 3。
设 n 为一正整数,考虑一个由非负整数组成的数组 [a1,…,an]。请计算满足如下条件的非负整数数组 [b1,…,bn] 的个数:
- 对所有 1≤i≤n,[b1,…,bi] 的 (n−i+1)-mex 等于 ai;
- 此外,对所有 1≤i≤n,均有 0≤bi≤n。
由于满足条件的数组个数可能极大,请将答案对 109+7 取模后输出。
输入格式
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≤2⋅105) — the length of the array a.
The second line of each test case contains n integers a1,…,an (0≤ai≤109).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,…,an(0≤ai≤109)。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output a single integer — the number of satisfying arrays b modulo 109+7.
对于每个测试用例,输出一个整数——满足条件的数组 b 的个数对 109+7 取模的结果。
输入输出样例
输入#1
6 3 3 3 1 3 2 1 3 1 0 1 2 4 7 5 2 2 6 6 6 6 4 3 3
输出#1
6 0 1 0 0 360
说明/提示
In the first test case, the array a=[3,3,1]. There exist exactly six such arrays b that work. One such example is the array b=[2,0,2], which satisfies the conditions because:
- the 3-mex of [b1]=[2] is a1=3,
- the 2-mex of [b1,b2]=[2,0] is a2=3,
- the 1-mex of [b1,b2,b3]=[2,0,2] is a3=1.
In the second test case, the array a=[2,1,3]. It can be shown that no suitable array b exists.
在第一个测试用例中,数组 a=[3,3,1]。恰好存在六个满足条件的数组 b。其中一个例子是数组 b=[2,0,2],它满足条件,因为:
- [b1]=[2] 的 3-mex 为 a1=3,
- [b1,b2]=[2,0] 的 2-mex 为 a2=3,
- [b1,b2,b3]=[2,0,2] 的 1-mex 为 a3=1。
在第二个测试用例中,数组 a=[2,1,3]。可以证明,不存在满足条件的数组 b。
输入解题思路,AI测评打分。不知道怎么写?