CF2246C.0mar and Alternating Sums

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Define the alternating sum of an array bb of length kk to be ∑i=1k(−1)i+1bi\sum_{i = 1}^{k}(-1)^{i+1}b_i.

You are given a non-decreasing∗^{\text{∗}} array aa of length nn such that for all 1≤i≤n,1 \le i \le n, either ai=−1a_i = -1 or aia_i is a positive integer. Find the number of sequences 1≤i1<i2<…<ik≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_k \le n such that the alternating sum of the sequence ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} is 0.0. Since this number may be large, output it modulo 109+710^9+7.

Two sets i1,…,ik1i_1, \ldots, i_{k_1} and i1′,…,ik2′i'_1, \ldots, i'_{k_2} of indices are considered different if k1≠k2k_1 \neq k_2 or there exists a jj such that ij≠ij′.i_j \neq i'_j.

∗^{\text{∗}}A sequence a1,…,ana_1, \ldots, a_n is non-decreasing if a1≤a2≤…≤ana_1 \le a_2 \le \ldots \le a_n.

定义数组 bb(长度为 kk)的交错和为 ∑i=1k(−1)i+1bi\sum_{i = 1}^{k}(-1)^{i+1}b_i。

给定一个非递减∗^{\text{∗}} 数组 aa,长度为 nn,满足:对所有 1≤i≤n1 \le i \le n,均有 ai=−1a_i = -1 或 aia_i 为正整数。求满足如下条件的下标序列 1≤i1<i2<…<ik≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_k \le n 的个数:子序列 ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} 的交错和为 00。由于该数目可能很大,请输出其对 109+710^9+7 取模的结果。

若两个下标集合 i1,…,ik1i_1, \ldots, i_{k_1} 与 i1′,…,ik2′i'_1, \ldots, i'_{k_2} 满足 k1≠k2k_1 \neq k_2,或存在某个 jj 使得 ij≠ij′i_j \neq i'_j,则认为它们是不同的。

∗^{\text{∗}} 序列 a1,…,ana_1, \ldots, a_n 称为非递减,当且仅当 a1≤a2≤…≤ana_1 \le a_2 \le \ldots \le a_n。

输入格式

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 n (1≤n≤2⋅105)n \, (1 \le n \le 2 \cdot 10^5) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n — the elements of the array where ai=−1\mathbf{a_i = -1} or 1≤ai≤109\mathbf{1 \leq a_i \leq 10^9}. It is guaranteed that the array is non-decreasing.

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 \le n \le 2 \cdot 10^5)—— 数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n —— 数组的元素,其中 ai=−1\mathbf{a_i = -1} 或 1≤ai≤109\mathbf{1 \leq a_i \leq 10^9}。保证该数组是非递减的。

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

输出格式

For each testcase, output a single integer — the number of subsequences that have an alternating sum of zero modulo 109+710^9 +7. A subsequence of length 00 is considered to have an alternating sum of zero.

对于每个测试用例,输出一个整数——交替和模 109+710^9 +7 等于零的子序列个数。长度为 00 的子序列被视为具有交替和零。

输入输出样例

  • 输入#1

    4
    5
    -1 1 1 2 3
    3
    1 2 3
    4
    1 3 5 7
    14
    -1 -1 -1 1 2 2 3 3 3 5 5 5 5 5

    输出#1

    6
    1
    1
    1536

说明/提示

In the first example, the following subsequences have an alternating sum of zero:

∙\bullet

[],[],

∙\bullet

[a2,a3]=[1,1][a_2,a_3] = [1,1],

∙\bullet

[a1,a2,a4]=[−1,1,2][a_1, a_2, a_4] = [-1,1,2],

∙\bullet

[a1,a3,a4]=[−1,1,2][a_1, a_3, a_4] = [-1,1,2],

∙\bullet

[a1,a4,a5]=[−1,2,3][a_1, a_4, a_5] = [-1,2,3],

∙\bullet

[a1,a2,a3,a4,a5]=[−1,1,1,2,3].[a_1,a_2,a_3,a_4,a_5] = [-1,1,1,2,3].

In the second example, only the empty subsequence [][] has an alternating sum of zero.

在第一个例子中,以下子序列的交替和为零:

∙\bullet

[],[],

∙\bullet

[a2,a3]=[1,1][a_2,a_3] = [1,1],

∙\bullet

[a1,a2,a4]=[−1,1,2][a_1, a_2, a_4] = [-1,1,2],

∙\bullet

[a1,a3,a4]=[−1,1,2][a_1, a_3, a_4] = [-1,1,2],

∙\bullet

[a1,a4,a5]=[−1,2,3][a_1, a_4, a_5] = [-1,2,3],

∙\bullet

[a1,a2,a3,a4,a5]=[−1,1,1,2,3].[a_1,a_2,a_3,a_4,a_5] = [-1,1,1,2,3].

在第二个例子中,仅有空子序列 [][] 的交替和为零。

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

首页