PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000153. Eugene và dãy số (Eugene and an Array)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Eugene và dãy số (Eugene and an Array)
Eugene and an Array
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Eugene has an integer array . A nonempty contiguous interval is good if every nonempty contiguous interval contained in it has a nonzero sum. In other words, must hold for all . Count the good intervals. A nonzero sum of the whole interval alone is insufficient.
Input
- Line 1: integer , the number of elements.
- Line 2: integers in order.
Output
Print the number of qualifying intervals as one integer.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Example 1
Input
3
1 2 -3
Output
5
Explanation
The three singletons and both length-two intervals are good. The whole array sums to zero.
Example 2
Input
3
41 -41 41
Output
3
Explanation
All three singletons are good. Both length-two intervals sum to zero; the whole array contains them and is not good even though its sum is 41.