CF1738E.Balance Addicts
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an integer sequence a1,a2,…,an of length n , your task is to compute the number, modulo 998244353 , of ways to partition it into several non-empty continuous subsequences such that the sums of elements in the subsequences form a balanced sequence.
A sequence s1,s2,…,sk of length k is said to be balanced, if si=sk−i+1 for every 1≤i≤k . For example, [1,2,3,2,1] and [1,3,3,1] are balanced, but [1,5,15] is not.
Formally, every partition can be described by a sequence of indexes i1,i2,…,ik of length k with 1=i1<i2<⋯<ik≤n such that
- k is the number of non-empty continuous subsequences in the partition;
- For every 1≤j≤k , the j -th continuous subsequence starts with aij , and ends exactly before aij+1 , where ik+1=n+1 . That is, the j -th subsequence is aij,aij+1,…,aij+1−1 .
There are 2n−1 different partitions in total. Let s1,s2,…,sk denote the sums of elements in the subsequences with respect to the partition i1,i2,…,ik . Formally, for every 1≤j≤k , $$$$ s_j = \sum_{i=i_{j}}^{i_{j+1}-1} a_i = a_{i_j} + a_{i_j+1} + \dots + a_{i_{j+1}-1}. $$ For example, the partition \[1\\,|\\,2,3\\,|\\,4,5,6\] of sequence \[1,2,3,4,5,6\] is described by the sequence \[1,2,4\] of indexes, and the sums of elements in the subsequences with respect to the partition is \[1,5,15\] .
Two partitions i_1,i_2,dots,i_k and i′_1,i′_2,dots,i′_k′ (described by sequences of indexes) are considered to be different, if at least one of the following holds.
- kneqk′ ,
- i_jneqi′_j for some 1leqjleqminleftk,k′right$$.
输入格式
Each test contains multiple test cases. The first line contains an integer t ( 1≤t≤105 ) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer n ( 1≤n≤105 ), indicating the length of the sequence a .
The second line of each test case contains n integers a1,a2,…,an ( 0≤ai≤109 ), indicating the elements of the sequence a .
It is guaranteed that the sum of n over all test cases does not exceed 105 .
输出格式
For each test case, output the number of partitions with respect to which the sum of elements in each subsequence is balanced, modulo 998244353 .
输入输出样例
输入#1
6 1 1000000000 2 1 1 4 0 0 1 0 5 1 2 3 2 1 5 1 3 5 7 9 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
输出#1
1 2 3 4 2 150994942
说明/提示
For the first test case, there is only one way to partition a sequence of length 1 , which is itself and is, of course, balanced.
For the second test case, there are 2 ways to partition it:
- The sequence [1,1] itself, then s=[2] is balanced;
- Partition into two subsequences [1∣1] , then s=[1,1] is balanced.
For the third test case, there are 3 ways to partition it:
- The sequence [0,0,1,0] itself, then s=[1] is balanced;
- [0∣0,1∣0] , then s=[0,1,0] is balanced;
- [0,0∣1∣0] , then s=[0,1,0] is balanced.
For the fourth test case, there are 4 ways to partition it:
- The sequence [1,2,3,2,1] itself, then s=[9] is balanced;
- [1,2∣3∣2,1] , then s=[3,3,3] is balanced;
- [1∣2,3,2∣1] , then s=[1,7,1] is balanced;
- [1∣2∣3∣2∣1] , then s=[1,2,3,2,1] is balanced.
For the fifth test case, there are 2 ways to partition it:
- The sequence [1,3,5,7,9] itself, then s=[25] is balanced;
- [1,3,5∣7∣9] , then s=[9,7,9] is balanced.
For the sixth test case, every possible partition should be counted. So the answer is 232−1≡150994942(mod998244353) .