#PS0000127. Đếm giá trị thuộc khoảng trong một đoạn chỉ số (Range Value Counting)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm giá trị thuộc khoảng trong một đoạn chỉ số (Range Value Counting)
Range Value Counting
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array with values from 1 through 20, answer queries by counting positions in the inclusive index interval whose value lies in the inclusive value interval . Equal values at distinct positions count separately. The array never changes.
Input
The first line contains , the array length and query count.
The second line contains integers .
Each of the following lines contains four integers .
Output
Print lines, each containing the number of matching positions for its query.
Subtasks
- Subtask 1 (20 points): ; ; for each query; for every ; .
- Subtask 2 (30 points): ; ; for each query; for every ; ; .
- Subtask 3 (50 points): ; ; for each query; for every ; .
Example 1
Input
6 4
2 1 5 2 20 3
1 6 2 5
2 5 2 2
3 3 1 4
1 6 1 20
Output
4
1
0
6
Explanation
Query 1 counts positions 1,3,4,6, with values 2,5,2,3. Query 2 counts only position 4. Query 3 examines 5, which is outside the value range. Query 4 counts all six positions.