#SRD0000140. Tần suất giá trị trên đoạn tĩnh (Static Range Frequency)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tần suất giá trị trên đoạn tĩnh (Static Range Frequency)
Static Range Frequency
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of nonnegative integers . The sequence never changes while processing queries.
There are queries, each described by integers . For each query, count the indices satisfying both and .
The queried interval is half-open : it includes index but excludes . If , the interval is empty and the answer is . Sequence indices are zero-based.
Answer all queries in the given order.
Input
- The first line contains integers .
- The second line contains integers .
- Each of the following lines contains three integers describing query .
Output
Print lines. Line is the number of occurrences of value among ; print 0 for an empty interval.
Subtasks
- Subtask 1 (20 points): ; ; for every valid index.
- Subtask 2 (30 points): ; ; for every valid index.
- Subtask 3 (50 points): ; ; for every valid index.
Examples
Example 1
Input
5 5
3 7 3 2 3
0 5 3
1 4 3
0 0 3
2 5 7
0 5 2
Output
3
1
0
0
1
Explanation
The sequence is 3 7 3 2 3. In [0,5), value 3 occurs at indices 0,2,4: answer 3. In [1,4), only index 2 contains 3: answer 1. Interval [0,0) is empty: 0. There is no 7 in [2,5): 0. Finally, value 2 occurs only at index 3 of [0,5): 1.