PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000201. Số đoạn có tổng thuộc khoảng [A,B] (Count Subarray Sums in a Range)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Số đoạn có tổng thuộc khoảng [A,B] (Count Subarray Sums in a Range)
Count Subarray Sums in a Range
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers (possibly negative) and two bounds , count nonempty consecutive intervals satisfying . Intervals at different positions are counted separately.
Input
The first line contains . The second line contains exactly integers .
Output
Print the number of qualifying intervals.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
3 -2 2
-2 5 -1
Output
3
Explanation
The qualifying intervals are [1,1] (-2), [3,3] (-1), and [1,3] (2).
Example 2
Input
3 0 0
0 0 0
Output
6
Explanation
All six nonempty intervals sum to zero.