CF2159C.Twin Polynomials

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A polynomial f(x)=a0+a1x+a2x2+…+anxnf(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n is called a valid polynomial of degree nn if and only if aia_i is a non-negative integer for all 0≤i≤n0 \le i \le n and ana_n is not 00.

For a valid polynomial f(x)=a0+a1x+a2x2+…+anxnf(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n of degree nn, its twin polynomial g(x)g(x) is defined as: $$ g(x) = \sum_{i=0}^n i \cdot x^{a_i} $$ For example, for f(x)=1+2x+2x3f(x) = 1 + 2x + 2x^3, its twin polynomial is:

g(x)=0cdotx1+1cdotx2+2cdotx0+3cdotx2=0+x2+2+3x2=2+4x2g(x) = 0 \\cdot x^{1} + 1 \\cdot x^{2} + 2 \\cdot x^{0} + 3 \\cdot x^{2} = 0+x^2+2+3x^2= 2 + 4x^2

A valid polynomial f(x)f(x) of degree nn is called cool if and only if f(x)=g(x)f(x) = g(x). In other words, a valid polynomial of degree nn is cool if and only if its twin polynomial equals itself.

You are given an incomplete valid polynomial f(x)=a0+a1x+a2x2+…+anxnf(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n of degree nn. Some of aia_i have been determined, while others have not been determined. Additionally, it is guaranteed that a0a_0 and ana_n are not determined.

Please count the number of cool valid polynomials of degree nn that can be found by determining all undetermined aia_i's. Since the answer may be large, you need to output it modulo 1 000 000 0071\,000\,000\,007.

一个多项式 f(x)=a0+a1x+a2x2+…+anxnf(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n 被称为合法的 nn 次多项式,当且仅当对所有 0≤i≤n0 \le i \le n,系数 aia_i 均为非负整数,且首项系数 an≠0a_n \neq 0。

对于一个合法的 nn 次多项式 f(x)=a0+a1x+a2x2+…+anxnf(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n,其孪生多项式 g(x)g(x) 定义为:

g(x)=∑i=0ni⋅xaig(x) = \sum_{i=0}^n i \cdot x^{a_i}

例如,对 f(x)=1+2x+2x3f(x) = 1 + 2x + 2x^3,其孪生多项式为:

g(x)=0⋅x1+1⋅x2+2⋅x0+3⋅x2=0+x2+2+3x2=2+4x2g(x) = 0 \cdot x^{1} + 1 \cdot x^{2} + 2 \cdot x^{0} + 3 \cdot x^{2} = 0+x^2+2+3x^2= 2 + 4x^2

一个合法的 nn 次多项式 f(x)f(x) 被称为酷多项式(cool polynomial),当且仅当 f(x)=g(x)f(x) = g(x)。换言之,一个合法的 nn 次多项式是酷多项式,当且仅当它的孪生多项式等于它自身。

现给出一个不完整的合法 nn 次多项式 f(x)=a0+a1x+a2x2+…+anxnf(x) = a_0 + a_1x + a_2x^2 + \ldots + a_nx^n,其中部分系数 aia_i 已确定,其余未确定。此外,保证 a0a_0 和 ana_n 均未确定。

请计算:通过为所有未确定的 aia_i 赋值,能够得到多少个酷的合法 nn 次多项式。由于答案可能很大,请输出其对 1 000 000 0071\,000\,000\,007 取模的结果。

输入格式

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.

For each test case, the first line contains an integer nn (1≤n≤4⋅1051 \leq n \leq 4 \cdot 10^5).

The second line contains n+1n+1 integers a0,a1,…,ana_0, a_1, \ldots, a_n (−1≤ai≤109-1 \leq a_i \leq 10^9). Here, ai=−1a_i=-1 means aia_i has not been determined, while ai≠−1a_i \neq -1 means aia_i has been determined as its value.

It is guaranteed that a0a_0 and ana_n are always −1-1 in the input.

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

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

对于每个测试用例,第一行包含一个整数 nn(1≤n≤4⋅1051 \leq n \leq 4 \cdot 10^5)。

第二行包含 n+1n+1 个整数 a0,a1,…,ana_0, a_1, \ldots, a_n(−1≤ai≤109-1 \leq a_i \leq 10^9)。其中,ai=−1a_i = -1 表示 aia_i 尚未确定;而 ai≠−1a_i \neq -1 表示 aia_i 已被确定为其给定值。

保证输入中 a0a_0 和 ana_n 恒为 −1-1。

保证所有测试用例的 nn 值之和不超过 4⋅1054 \cdot 10^5。

输出格式

For each test case, output the number of cool valid polynomials of degree nn found by determining the undetermined aia_i's, modulo 1 000 000 0071\,000\,000\,007.

对于每个测试用例,输出通过确定未定系数 aia_i 所找到的次数为 nn 的“酷”有效多项式的数量,结果对 1 000 000 0071\,000\,000\,007 取模。

输入输出样例

  • 输入#1

    6
    1
    -1 -1
    2
    -1 2 -1
    2
    -1 -1 -1
    3
    -1 -1 3 -1
    3
    -1 2 3 -1
    5
    -1 -1 -1 1 0 -1

    输出#1

    1
    1
    3
    2
    0
    3

说明/提示

In the first test case, only f(x)=xf(x) = x satisfies the condition above.

In the second test case, only f(x)=x2+2xf(x) = x^2 + 2x satisfies the condition above.

In the third test case, f(x)=2x2+xf(x) = 2x^2 + x, f(x)=x2+2xf(x) = x^2 + 2x, and f(x)=2x2+1f(x) = 2x^2 + 1 satisfy the condition above.

在第一个测试用例中,只有 f(x)=xf(x) = x 满足上述条件。

在第二个测试用例中,只有 f(x)=x2+2xf(x) = x^2 + 2x 满足上述条件。

在第三个测试用例中,f(x)=2x2+xf(x) = 2x^2 + x、f(x)=x2+2xf(x) = x^2 + 2x 和 f(x)=2x2+1f(x) = 2x^2 + 1 满足上述条件。

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

首页