Treasure Hunt
Time limit5sMemory limit512 MB
Given n treasure points and m axis-aligned rectangles, count how many points fall inside each rectangle (boundaries included).
- Level
Medium6 of 10
- Topics
- Sorting, Binary search, Prefix sum, Geometry
- Solved
- No attempts yet
Problem
Taro has come to a plaza to look for treasure. Many treasures are buried in this plaza, and since Taro has a state-of-the-art machine, he knows exactly where every treasure is buried. The plaza is very large, so Taro decided to pick a region and search for treasure there, but there are so many treasures that he cannot immediately tell which ones lie inside that region. So Taro decided to count the number of treasures inside the region.
Input
n m
x1 y1
x2 y2
...
xn yn
x11 y11 x12 y12
x21 y21 x22 y22
...
xm1 ym1 xm2 ym2
nis the number of treasures buried in the plaza.mis the number of regions to examine.- Lines 2 through
n+1give the coordinates where each treasure is buried. - Lines
n+2throughn+m+1give each region to examine. - The positive x direction is east, and the positive y direction is north.
- Each region is a rectangle, where
xi1andyi1are the coordinates of the southwest vertex, andxi2andyi2are the coordinates of the northeast vertex.
Output
C1
C2
...
Cm
- Print the number of treasures contained in each region, one per line.
Constraints
1 ≤ n ≤ 50001 ≤ m ≤ 5×105|xi|, |yi| ≤ 109 (1 ≤ i ≤ n)|xi1|, |yi1|, |xi2|, |yi2| ≤ 109 (1 ≤ i ≤ m)xi1 ≤ xi2, yi1 ≤ yi2 (1 ≤ i ≤ m)- All input is given as integers.