PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000271. Phân biệt đoạn đóng và đoạn nửa mở (Closed and Half-open Intervals)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phân biệt đoạn đóng và đoạn nửa mở (Closed and Half-open Intervals)
Closed and Half-open Intervals
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given intervals on the integer number line, type includes integers , and type includes integers . For each query , count intervals containing it. Duplicate intervals count separately. A half-open interval is empty; a closed interval contains one point.
Input
First line: . Next lines: . Last line: integers .
Output
Print integers on one line in query order.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; for every interval.
- Subtask 3 (50 points): ; ; ; .
Example 1
Input
4 5
0 1 3
1 1 3
0 3 3
1 3 3
0 1 2 3 4
Output
0 2 2 2 0
Explanation
No interval contains 0 or 4. Both first intervals contain 1 and 2. At 3 only the two closed intervals count; is empty.
Example 2
Input
3 4
0 -2 0
1 -2 0
1 0 2
-2 -1 0 2
Output
2 2 2 0
Explanation
At -2 and -1 the first two intervals count; at 0 the first closed and third half-open interval count; 2 is excluded.