PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000197. Nhiều truy vấn đếm đoạn có tổng không nhỏ hơn K (Multiple Subarray Sum Threshold Queries)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nhiều truy vấn đếm đoạn có tổng không nhỏ hơn K (Multiple Subarray Sum Threshold Queries)
Multiple Subarray Sum Threshold Queries
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers and queries, for each integer threshold count nonempty consecutive intervals satisfying . Queries are independent and the array never changes. Intervals at different positions are counted separately.
Input
The first line contains . The second contains exactly integers . Each of the next lines contains one integer .
Output
Print lines, each containing the count for the corresponding query.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Example 1
Input
3 4
2 -1 3
0
3
4
5
Output
5
2
1
0
Explanation
The six sums are 2, 1, 4, -1, 2, 3. Five are nonnegative, two are at least 3, one is at least 4, and none is at least 5.
Example 2
Input
2 3
0 0
0
1
-1
Output
3
0
3
Explanation
All three intervals sum to zero; thresholds 0 and -1 accept all three.