#P2313. Counting Points Inside Shapes
Counting Points Inside Shapes
Counting Points Inside Shapes
Tom is a very active child. Today he got interested in compasses and rulers, and started drawing countless rectangles and circles on a huge white paper. While drawing, he accidentally spilled his popcorn, and the white paper was covered with many little dots. Tom noticed that some dots fall inside the drawn figures while others fall outside. For each dot, he wants to know in how many figures it lies. Your task is: given N figures (each one is either a rectangle with sides parallel to the coordinate axes or a circle) and M points on the plane, count for each point the number of figures in which it lies. A point is considered to be inside a rectangle if its coordinates (x, y) satisfy \(\min(x_1,x_2) \le x \le \max(x_1,x_2)\) and \(\min(y_1,y_2) \le y \le \max(y_1,y_2)\). A point is inside a circle if \((x - x_0)^2 + (y - y_0)^2 \le r^2\) (note that points on the boundary are regarded as inside).
inputFormat
The input begins with two integers N and M, representing the number of figures and the number of points respectively.
Following are N lines each describing a figure. Each line starts with a character:
- If the character is
R
, it is followed by four numbersx1 y1 x2 y2
, representing the coordinates of two opposite corners of a rectangle. - If the character is
C
, it is followed by three numbersx0 y0 r
, where(x0, y0)
is the center of the circle andr
is its radius.
Then follow M lines, each containing two numbers representing the coordinates of a point.
outputFormat
Output M lines. Each line should contain a single integer indicating the number of figures that contain the corresponding point.
sample
3 3
R 0 0 4 4
C 5 5 2
R 3 3 6 6
1 1
4 4
6 6
1
3
2
</p>