CF2224A.Zhily and Array Operating

入门

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Deep in the wilderness, Zhily and Jily discovered a series of gathering places that contain abstract logic. Some of these gathering places harbor inconsistent errors in their logic, which may collapse at any moment. They hope to transmit logic between adjacent gathering places through reasonable transfer arrangements so that as many gathering places as possible can eventually restore logical stability.

You are given an array aa of nn integers. You can perform the following operation any number of times:

  • Choose an index ii (1≤i<n1 \le i \lt n) and assign ai←ai+ai+1a_i\gets a_i+a_{i+1}.

Each index can be chosen at most once.

Find the maximum number of positive integers in the final array after all operations.

在荒野深处,芝莉和吉莉发现了一系列蕴含抽象逻辑的聚集地。其中一些聚集地的逻辑存在不一致的错误,随时可能崩溃。她们希望通过对相邻聚集地进行合理的逻辑传递安排,使得尽可能多的聚集地最终恢复逻辑稳定性。

给你一个包含 nn 个整数的数组 aa。你可以执行以下操作任意多次:

  • 选择一个下标 ii(1≤i<n1 \le i \lt n),并令 ai←ai+ai+1a_i\gets a_i+a_{i+1}。

每个下标最多只能被选择一次。

求所有操作完成后,数组中正整数的最大可能个数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤2⋅1052\leq n \leq 2\cdot 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (−109≤ai≤109-10^9\leq a_i\leq 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052\leq n \leq 2\cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(−109≤ai≤109-10^9\leq a_i\leq 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot10^5。

输出格式

For each test case, you should output a single line containing an integer kk, the number of positive numbers in the final sequence.

对于每个测试用例,你应该输出一行,包含一个整数 kk,表示最终序列中正数的个数。

输入输出样例

  • 输入#1

    4
    5
    0 -1 3 -3 0
    5
    0 -2 1 2 3
    5
    0 1 0 1 0
    2
    1000000000 -1000000000

    输出#1

    3
    5
    4
    1

说明/提示

In the first test case, the array aa is operated on by the following process:

[0,−1,3,−3,0]→[0,2,3,−3,0]→[2,2,3,−3,0][0,-1,3,-3,0]\to [0,\color{red}{2},3,-3,0]\to [\color{red}{2},2,3,-3,0].

There are 33 positive numbers in the final array, and it can be proven that this is the maximum count of positive integers.

In the second test case, the final array can be:[4,4,6,5,3][4,4,6,5,3], which is operated on by the following process:

[0,−2,1,2,3]→[0,−2,1,5,3]→[0,−2,6,5,3]→[0,4,6,5,3]→[4,4,6,5,3][0,-2,1,2,3]\to [0,-2,1,\color{red}{5},3]\to [0,-2,\color{red}{6},5,3]\to [0,\color{red}{4},6,5,3]\to [\color{red}{4},4,6,5,3].

In the third test case, the final array can be:[1,1,1,1,0][1,1,1,1,0], which is operated on by the following process:

[0,1,0,1,0]→[1,1,0,1,0]→[1,1,1,1,0][0,1,0,1,0]\to [\color{red}{1},1,0,1,0]\to [1,1,\color{red}{1},1,0].

在第一个测试用例中,数组 aa 经历如下操作过程:

[0,−1,3,−3,0]→[0,2,3,−3,0]→[2,2,3,−3,0][0,-1,3,-3,0]\to [0,\color{red}{2},3,-3,0]\to [\color{red}{2},2,3,-3,0]。

最终数组中有 33 个正数,且可以证明这是正整数个数的最大值。

在第二个测试用例中,最终数组可以是:[4,4,6,5,3][4,4,6,5,3],其操作过程如下:

[0,−2,1,2,3]→[0,−2,1,5,3]→[0,−2,6,5,3]→[0,4,6,5,3]→[4,4,6,5,3][0,-2,1,2,3]\to [0,-2,1,\color{red}{5},3]\to [0,-2,\color{red}{6},5,3]\to [0,\color{red}{4},6,5,3]\to [\color{red}{4},4,6,5,3]。

在第三个测试用例中,最终数组可以是:[1,1,1,1,0][1,1,1,1,0],其操作过程如下:

[0,1,0,1,0]→[1,1,0,1,0]→[1,1,1,1,0][0,1,0,1,0]\to [\color{red}{1},1,0,1,0]\to [1,1,\color{red}{1},1,0]。

输入解题思路,AI测评打分。不知道怎么写?

首页