#FT0000146. Nỗi khó khăn của người làm vườn (The Gardener’s Trouble)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nỗi khó khăn của người làm vườn (The Gardener’s Trouble)
The Gardener’s Trouble
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
A royal garden contains trees. Tree has integer position . Several distinct trees may share one coordinate and each must be counted separately.
There are independent rectangle queries. Query gives bottom-left corner and top-right corner , with and . Count all trees satisfying and simultaneously. All rectangle boundaries are included. Queries do not alter the garden.
Input
The first line contains . The next lines contain the coordinates of the trees. The final lines contain for each rectangle.
Output
Print lines; line is the number of trees in rectangle .
Subtasks
- Subtask 1 (30 points): ; ; ; , ; multiple trees may have identical coordinates.
- Subtask 2 (30 points): ; ; ; , ; multiple trees may have identical coordinates.
- Subtask 3 (40 points): ; ; ; , ; multiple trees may have identical coordinates.
Examples
Example 1
Input
3 2
0 0
0 0
2 3
0 0 0 0
0 0 2 3
Output
2
3
Explanation
The first rectangle covers only , where two trees stand. The second rectangle includes both and (boundaries included), thus contains all three trees.
Example 2
Input
4 3
0 2
1 1
3 3
1 1
1 1 1 1
0 0 3 3
2 0 3 2
Output
2
4
0
Explanation
Two trees share position , giving 2 for the first query. All four trees lie in the second rectangle. The third rectangle requires and ; no tree satisfies both, since is too high.