PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000103. Truy vấn đếm trong khoảng (Fast Search)
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 đếm trong khoảng (Fast Search)
Fast Search
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array with possible duplicates, for each query count positions satisfying , counting repeated values separately.
Input
The first line contains , the next line contains integers, followed by and then lines each containing .
Output
For each query, print the count on its own line.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5
10 1 10 3 4
4
1 10
2 9
3 4
2 2
Output
5
2
2
0
Explanation
Array contains five values in . Only lie in , and also in . No entry equals . The four counts are 5, 2, 2, 0.