CF1426D.Non-zero Segments

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Kolya got an integer array a1,a2,…,ana_1, a_2, \dots, a_n. The array can contain both positive and negative integers, but Kolya doesn't like 00, so the array doesn't contain any zeros.

Kolya doesn't like that the sum of some subsegments of his array can be 00. The subsegment is some consecutive segment of elements of the array.

You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum 00. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, 00, any by absolute value, even such a huge that they can't be represented in most standard programming languages).

Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum 00.

科里亚得到了一个整数数组 a1,a2,…,ana_1, a_2, \dots, a_n。该数组可包含正整数和负整数,但科里亚不喜欢 00,因此数组中不包含任何零。

科里亚不喜欢他的数组中存在某些子段(即数组中一段连续的元素)的和为 00。

你需要帮助科里亚修改该数组,使得修改后的数组中不再包含任何和为 00 的子段。为达成此目标,你可以在数组任意两个相邻元素之间插入任意整数(这些整数可以是任意值:正数、负数、00,绝对值可任意大,甚至大到无法被大多数标准编程语言表示)。

你的任务是求出:为使最终数组中不存在任何和为 00 的子段,所需插入的整数的最少个数。

输入格式

The first line of the input contains one integer nn (2≤n≤200 0002 \le n \le 200\,000) — the number of elements in Kolya's array.

The second line of the input contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (−109≤ai≤109,ai≠0-10^{9} \le a_i \le 10^{9}, a_i \neq 0) — the description of Kolya's array.

输入的第一行包含一个整数 nn(2≤n≤200 0002 \le n \le 200\,000)—— 表示 Kolya 数组中元素的个数。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(−109≤ai≤109,ai≠0-10^{9} \le a_i \le 10^{9}, a_i \neq 0)—— 表示 Kolya 数组的描述。

输出格式

Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum 00.

输出需要插入到科里亚数组中的整数的最小数量,使得得到的数组不包含任何和为 00 的子段。

输入输出样例

  • 输入#1

    4
    1 -5 3 2

    输出#1

    1
  • 输入#2

    5
    4 -2 3 -9 2

    输出#2

    0
  • 输入#3

    9
    -1 1 -1 1 -1 1 1 -1 -1

    输出#3

    6
  • 输入#4

    8
    16 -5 -11 -15 10 5 4 -4

    输出#4

    3

说明/提示

Consider the first example. There is only one subsegment with the sum 00. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer 11 between second and third elements of the array.

There are no subsegments having sum 00 in the second example so you don't need to do anything.

考虑第一个例子。只有一个子段的和为 00,该子段起始于第二个元素,终止于第四个元素。此时只需插入一个元素,即可使数组中不再包含任何和为零的子段。例如,可以在数组的第二个元素与第三个元素之间插入整数 11。

第二个例子中不存在和为 00 的子段,因此无需进行任何操作。

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

首页