CF1748C.Zero-Sum Prefixes
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The score of an array v1,v2,…,vn is defined as the number of indices i ( 1≤i≤n ) such that v1+v2+…+vi=0 .
You are given an array a1,a2,…,an of length n . You can perform the following operation multiple times:
- select an index i ( 1≤i≤n ) such that ai=0 ;
- then replace ai by an arbitrary integer.
What is the maximum possible score of a that can be obtained by performing a sequence of such operations?
输入格式
Each test contains multiple test cases. The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The first line of each test case contains one integer n ( 1≤n≤2⋅105 ) — the length of the array a .
The second line of each test case contains n integers a1,a2,…,an ( −109≤ai≤109 ) — array a .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, print the maximum possible score of the array a after performing a sequence of operations.
输入输出样例
输入#1
5 5 2 0 1 -1 0 3 1000000000 1000000000 0 4 0 0 0 0 8 3 0 2 -10 10 -30 30 0 9 1 0 0 1 -1 0 1 0 -1
输出#1
3 1 4 4 5
说明/提示
In the first test case, it is optimal to change the value of a2 to −2 in one operation.
The resulting array a will be [2,−2,1,−1,0] , with a score of 3 :
- a1+a2=2−2=0 ;
- a1+a2+a3+a4=2−2+1−1=0 ;
- a1+a2+a3+a4+a5=2−2+1−1+0=0 .
In the second test case, it is optimal to change the value of a3 to −2000000000 , giving us an array with a score of 1 .
In the third test case, it is not necessary to perform any operations.