PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000203. Đếm đoạn theo tổng và độ dài (Count Subarrays by Sum and Length)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đoạn theo tổng và độ dài (Count Subarrays by Sum and Length)
Count Subarrays by Sum and Length
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , length bounds and sum bounds , count nonempty consecutive intervals satisfying both and . Indices are 1-based; 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
4 1 2 2 3
1 2 -1 3
Output
4
Explanation
Intervals [2,2], [4,4], [1,2], [3,4] have sums 2, 3, 3, 2.
Example 2
Input
3 2 2 0 0
0 0 0
Output
2
Explanation
Both intervals of length 2 sum to zero.