CF1748C.Zero-Sum Prefixes
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
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?
数组 v1,v2,…,vn 的得分定义为满足 v1+v2+…+vi=0 的下标 i(其中 1≤i≤n)的个数。
给定一个长度为 n 的数组 a1,a2,…,an。你可以执行以下操作任意多次:
- 选择一个下标 i(1≤i≤n),满足 ai=0;
- 然后将 ai 替换为任意整数。
通过执行若干次上述操作,a 数组所能达到的最大可能得分是多少?
输入格式
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.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)—— 数组 a。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print the maximum possible score of the array a after performing a sequence of operations.
对于每个测试用例,输出执行一系列操作后数组 a 的最大可能得分。
输入输出样例
输入#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.
在第一个测试用例中,最优策略是通过一次操作将 a2 的值修改为 −2。
得到的数组 a 将为 [2,−2,1,−1,0],其得分为 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。
在第二个测试用例中,最优策略是将 a3 的值修改为 −2000000000,从而得到一个得分为 1 的数组。
在第三个测试用例中,无需执行任何操作。
输入解题思路,AI测评打分。不知道怎么写?