PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000123. Đếm kiện cỏ trong đoạn (Counting Haybales)
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 kiện cỏ trong đoạn (Counting Haybales)
Counting Haybales
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
A farmer places haybales at distinct integer positions on a straight road. Each of queries gives an inclusive interval . Count the haybales whose positions lie inside that interval, including both endpoints.
Input
The first line contains . The second line contains pairwise distinct haybale positions . Each of the following lines contains interval endpoints .
Output
Print lines; line contains the haybale count in query .
Subtasks
- Subtask 1 (20 points): ; ; all are distinct, , .
- Subtask 2 (30 points): ; ; all are distinct, , .
- Subtask 3 (50 points): ; ; all are distinct, , .
Examples
Input
4 6
3 2 7 5
2 3
2 4
2 5
2 7
4 6
8 10
Output
2
2
3
4
1
0
Explanation
Sorted haybale positions are . The intervals , , , , , and contain respectively , , , , , and bales. Thus the six output lines are 2 2 3 4 1 0 in this order.