PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000206. Đếm đoạn có trung bình trong [A,B] (Count Subarrays with Average 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
Đếm đoạn có trung bình trong [A,B] (Count Subarrays with Average in a Range)
Count Subarrays with Average in a Range
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers and two integers , count nonempty consecutive intervals satisfying . Both bounds are inclusive; 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 3
1 3 2
Output
5
Explanation
The five intervals are [2,2], [3,3], [1,2], [2,3], [1,3]; their averages are 3, 2, 2, 2.5, 2.
Example 2
Input
3 0 0
-1 1 0
Output
3
Explanation
Intervals [1,2], [3,3], [1,3] sum to zero and thus have average exactly zero.