CF2246C.0mar and Alternating Sums
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Define the alternating sum of an array b of length k to be ∑i=1k(−1)i+1bi.
You are given a non-decreasing∗ array a of length n such that for all 1≤i≤n, either ai=−1 or ai is a positive integer. Find the number of sequences 1≤i1<i2<…<ik≤n such that the alternating sum of the sequence ai1,ai2,…,aik is 0. Since this number may be large, output it modulo 109+7.
Two sets i1,…,ik1 and i1′,…,ik2′ of indices are considered different if k1=k2 or there exists a j such that ij=ij′.
∗A sequence a1,…,an is non-decreasing if a1≤a2≤…≤an.
定义数组 b(长度为 k)的交错和为 ∑i=1k(−1)i+1bi。
给定一个非递减∗ 数组 a,长度为 n,满足:对所有 1≤i≤n,均有 ai=−1 或 ai 为正整数。求满足如下条件的下标序列 1≤i1<i2<…<ik≤n 的个数:子序列 ai1,ai2,…,aik 的交错和为 0。由于该数目可能很大,请输出其对 109+7 取模的结果。
若两个下标集合 i1,…,ik1 与 i1′,…,ik2′ 满足 k1=k2,或存在某个 j 使得 ij=ij′,则认为它们是不同的。
∗ 序列 a1,…,an 称为非递减,当且仅当 a1≤a2≤…≤an。
输入格式
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.
The second line of each test case contains n integers a1,a2,…,an — the elements of the array where ai=−1 or 1≤ai≤109. It is guaranteed that the array is non-decreasing.
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)—— 数组的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an —— 数组的元素,其中 ai=−1 或 1≤ai≤109。保证该数组是非递减的。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each testcase, output a single integer — the number of subsequences that have an alternating sum of zero modulo 109+7. A subsequence of length 0 is considered to have an alternating sum of zero.
对于每个测试用例,输出一个整数——交替和模 109+7 等于零的子序列个数。长度为 0 的子序列被视为具有交替和零。
输入输出样例
输入#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:
∙
[],
∙
[a2,a3]=[1,1],
∙
[a1,a2,a4]=[−1,1,2],
∙
[a1,a3,a4]=[−1,1,2],
∙
[a1,a4,a5]=[−1,2,3],
∙
[a1,a2,a3,a4,a5]=[−1,1,1,2,3].
In the second example, only the empty subsequence [] has an alternating sum of zero.
在第一个例子中,以下子序列的交替和为零:
∙
[],
∙
[a2,a3]=[1,1],
∙
[a1,a2,a4]=[−1,1,2],
∙
[a1,a3,a4]=[−1,1,2],
∙
[a1,a4,a5]=[−1,2,3],
∙
[a1,a2,a3,a4,a5]=[−1,1,1,2,3].
在第二个例子中,仅有空子序列 [] 的交替和为零。
输入解题思路,AI测评打分。不知道怎么写?