#FT0000141. Đếm hình chữ nhật chứa mỗi điểm (Count Number of Rectangles Containing Each Point)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm hình chữ nhật chứa mỗi điểm (Count Number of Rectangles Containing Each Point)
Count Number of Rectangles Containing Each Point
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are axis-aligned rectangles in the plane. Every rectangle has bottom-left corner ; rectangle has top-right corner and therefore contains exactly the points satisfying and . The boundary is included.
You are also given distinct points . For each point, count how many rectangles contain it. Rectangles may overlap or contain one another, but all pairs are distinct. Count each rectangle once, and output the answers in input point order.
Input
The first line contains . The next lines contain ; the final lines contain .
Output
Print lines; line gives the number of rectangles containing point .
Subtasks
- Subtask 1 (20 points): ; ; ; All rectangle pairs are distinct; all query points are distinct.
- Subtask 2 (30 points): ; ; ; All rectangle pairs are distinct; all query points are distinct.
- Subtask 3 (50 points): ; ; ; All rectangle pairs are distinct; all query points are distinct.
Examples
Example 1
Input
3 2
1 2
2 3
2 5
2 1
1 4
Output
2
1
Explanation
Point belongs to rectangles and ; is too narrow. Point belongs only to rectangle .
Example 2
Input
3 2
1 1
2 2
3 3
1 3
1 1
Output
1
3
Explanation
Only contains point . All three rectangles contain , including the point on the boundary of rectangle .