CF1610D.Not Quite Lee
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Lee couldn't sleep lately, because he had nightmares. In one of his nightmares (which was about an unbalanced global round), he decided to fight back and propose a problem below (which you should solve) to balance the round, hopefully setting him free from the nightmares.
A non-empty array b1,b2,…,bm is called good, if there exist m integer sequences which satisfy the following properties:
- The i-th sequence consists of bi consecutive integers (for example if bi=3 then the i-th sequence can be (−1,0,1) or (−5,−4,−3) but not (0,−1,1) or (1,2,3,4)).
- Assuming the sum of integers in the i-th sequence is sumi, we want sum1+sum2+…+summ to be equal to 0.
You are given an array a1,a2,…,an. It has 2n−1 nonempty subsequences. Find how many of them are good.
As this number can be very large, output it modulo 109+7.
An array c is a subsequence of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements.
Lee 最近一直睡不着,因为他总是做噩梦。在其中一个噩梦里(梦到了一场不平衡的全球赛),他决定奋起反击,并提出了下面这道题(你需要解决它),以期让比赛恢复平衡,从而让他摆脱噩梦。
一个非空数组 b1,b2,…,bm 被称为好数组,当且仅当存在 m 个整数序列,满足以下性质:
- 第 i 个序列由 bi 个连续整数构成(例如,若 bi=3,则第 i 个序列可以是 (−1,0,1) 或 (−5,−4,−3),但不能是 (0,−1,1) 或 (1,2,3,4));
- 设第 i 个序列中所有整数之和为 sumi,我们要求 sum1+sum2+…+summ=0。
现给定一个数组 a1,a2,…,an。它共有 2n−1 个非空子序列。请计算其中有多少个是好数组。
由于答案可能非常大,请输出其对 109+7 取模的结果。
数组 c 是数组 d 的一个子序列,当且仅当 c 可通过从 d 中删除若干(可能为零个或全部)元素得到。
输入格式
The first line contains a single integer n (2≤n≤2⋅105) — the size of array a.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — elements of the array.
第一行包含一个整数 n(2≤n≤2⋅105)——数组 a 的大小。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)——数组的元素。
输出格式
Print a single integer — the number of nonempty good subsequences of a, modulo 109+7.
输出一个整数——数组 a 的非空“好”子序列的个数,对 109+7 取模。
输入输出样例
输入#1
4 2 2 4 7
输出#1
10
输入#2
10 12391240 103904 1000000000 4142834 12039 142035823 1032840 49932183 230194823 984293123
输出#2
996
说明/提示
For the first test, two examples of good subsequences are [2,7] and [2,2,4,7]:
For b=[2,7] we can use (−3,−4) as the first sequence and (−2,−1,…,4) as the second. Note that subsequence [2,7] appears twice in [2,2,4,7], so we have to count it twice.
Green circles denote (−3,−4) and orange squares denote (−2,−1,…,4).
For b=[2,2,4,7] the following sequences would satisfy the properties: (−1,0), (−3,−2), (0,1,2,3) and (−3,−2,…,3)
对于第一个测试用例,两个优秀的子序列示例是 [2,7] 和 [2,2,4,7]:
对于 b=[2,7],我们可以取 (−3,−4) 作为第一个序列,取 (−2,−1,…,4) 作为第二个序列。注意子序列 [2,7] 在 [2,2,4,7] 中出现了两次,因此需将其计数两次。
绿色圆圈表示 (−3,−4),橙色方块表示 (−2,−1,…,4)。
对于 b=[2,2,4,7],以下序列满足题目要求:(−1,0)、(−3,−2)、(0,1,2,3) 和 (−3,−2,…,3)。
输入解题思路,AI测评打分。不知道怎么写?