PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000222. Truy vấn tần suất trên đoạn (Range Frequency 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
Truy vấn tần suất trên đoạn (Range Frequency Queries)
Range Frequency Queries
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An immutable integer array is indexed from zero. A query specifies . Count the indices between and , inclusive, satisfying . Different positions containing the same value count separately.
Input
The first line gives integers , the array length and query count.
The second line contains the integers .
Each of the next lines gives integers : the two inclusive endpoints and the value to count.
Output
Print lines, one count for each query in input order.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
6 4
2 5 2 2 7 5
0 5 2
1 3 2
4 4 2
0 5 9
Output
3
2
0
0
Explanation
Value occurs at indices . The first interval contains all three; contains indices only. The singleton contains , and is absent from the array, giving zero for both remaining queries.