CF1748C.Zero-Sum Prefixes

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The score of an array v1,v2,,vnv_1,v_2,\ldots,v_n is defined as the number of indices ii ( 1in1 \le i \le n ) such that v1+v2++vi=0v_1+v_2+\ldots+v_i = 0 .

You are given an array a1,a2,,ana_1,a_2,\ldots,a_n of length nn . You can perform the following operation multiple times:

  • select an index ii ( 1in1 \le i \le n ) such that ai=0a_i=0 ;
  • then replace aia_i by an arbitrary integer.

What is the maximum possible score of aa that can be obtained by performing a sequence of such operations?

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains one integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the length of the array aa .

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n ( 109ai109-10^9 \le a_i \le 10^9 ) — array aa .

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print the maximum possible score of the array aa 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 a2a_2 to 2-2 in one operation.

The resulting array aa will be [2,2,1,1,0][2,-2,1,-1,0] , with a score of 33 :

  • a1+a2=22=0a_1+a_2=2-2=0 ;
  • a1+a2+a3+a4=22+11=0a_1+a_2+a_3+a_4=2-2+1-1=0 ;
  • a1+a2+a3+a4+a5=22+11+0=0a_1+a_2+a_3+a_4+a_5=2-2+1-1+0=0 .

In the second test case, it is optimal to change the value of a3a_3 to 2000000000-2\,000\,000\,000 , giving us an array with a score of 11 .

In the third test case, it is not necessary to perform any operations.

首页