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≤n0 \leq b_i \leq 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 kk, define the kk-mex of a collection of integers SS to be the kk-th smallest nonnegative integer not present in SS. For instance, the 11-mex and 22-mex of [1,2,1][1, 2, 1] are 00 and 33, respectively.

Let nn be a positive integer, and consider an array of nonnegative integers [a1,…,an][a_1, \ldots, a_n]. Compute the number of arrays of nonnegative integers [b1,…,bn][b_1, \ldots, b_n] such that:

  • For all 1≤i≤n1 \leq i \leq n, the (n−i+1)(n-i+1)-mex of [b1,…,bi][b_1, \ldots, b_i] is aia_i.
  • Additionally, for all 1≤i≤n1 \leq i \leq n, 0≤bi≤n0 \leq b_i \leq n.

Since the number of such arrays may be large, output the answer modulo 109+710^9 + 7.

建筑大师基地进攻(第二阶段)——Supercell,《部落冲突》

本题为计数版本。与其它版本的区别在于:在本版本中,你需要统计满足 0≤bi≤n0 \leq b_i \leq n 的构造方案总数。仅当你已解决本题的所有版本后,才可进行 Hack。

建筑大师讨厌重复性工作——修缮基地、将城镇大厅升级十五次、以及再做一道关于 MEX 的编程题。因此,本题将不是你所熟悉的普通 MEX 问题。

对任意正整数 kk,定义整数集合 SS 的 kk-mex 为 SS 中未出现的第 kk 小的非负整数。例如,数组 [1,2,1][1, 2, 1] 的 11-mex 和 22-mex 分别为 00 和 33。

设 nn 为一正整数,考虑一个由非负整数组成的数组 [a1,…,an][a_1, \ldots, a_n]。请计算满足如下条件的非负整数数组 [b1,…,bn][b_1, \ldots, b_n] 的个数:

  • 对所有 1≤i≤n1 \leq i \leq n,[b1,…,bi][b_1, \ldots, b_i] 的 (n−i+1)(n-i+1)-mex 等于 aia_i;
  • 此外,对所有 1≤i≤n1 \leq i \leq n,均有 0≤bi≤n0 \leq b_i \leq n。

由于满足条件的数组个数可能极大,请将答案对 109+710^9 + 7 取模后输出。

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,…,ana_1, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,…,ana_1, \ldots, a_n(0≤ai≤1090 \leq a_i \leq 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the number of satisfying arrays bb modulo 109+710^9 + 7.

对于每个测试用例,输出一个整数——满足条件的数组 bb 的个数对 109+710^9 + 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]a = [3, 3, 1]. There exist exactly six such arrays bb that work. One such example is the array b=[2,0,2]b = [2, 0, 2], which satisfies the conditions because:

  • the 33-mex of [b1]=[2][b_1] = [2] is a1=3a_1 = 3,
  • the 22-mex of [b1,b2]=[2,0][b_1, b_2] = [2, 0] is a2=3a_2 = 3,
  • the 11-mex of [b1,b2,b3]=[2,0,2][b_1, b_2, b_3] = [2, 0, 2] is a3=1a_3 = 1.

In the second test case, the array a=[2,1,3]a = [2, 1, 3]. It can be shown that no suitable array bb exists.

在第一个测试用例中,数组 a=[3,3,1]a = [3, 3, 1]。恰好存在六个满足条件的数组 bb。其中一个例子是数组 b=[2,0,2]b = [2, 0, 2],它满足条件,因为:

  • [b1]=[2][b_1] = [2] 的 33-mex 为 a1=3a_1 = 3,
  • [b1,b2]=[2,0][b_1, b_2] = [2, 0] 的 22-mex 为 a2=3a_2 = 3,
  • [b1,b2,b3]=[2,0,2][b_1, b_2, b_3] = [2, 0, 2] 的 11-mex 为 a3=1a_3 = 1。

在第二个测试用例中,数组 a=[2,1,3]a = [2, 1, 3]。可以证明,不存在满足条件的数组 bb。

输入解题思路,AI测评打分。不知道怎么写?

首页