Points and Rectangles
Time limit2sMemory limit512 MB
Process point insertions and rectangle insertions online, after each query reporting how many (point, rectangle) pairs have the point inside or on the rectangle.
- Level
Medium7 of 10
- Topics
- Segment tree, Prefix sum, Sorting, Implementation
- Solved
- No attempts yet
Problem
You have an empty infinite two-dimensional plane and queries. There are two types of queries:
<1 x y>— add a point with the coordinates to the plane.<2 x1 y1 x2 y2>— add a rectangle whose lower left corner has the coordinates and whose upper right corner has the coordinates . The area of this rectangle can be zero, and a rectangle can degenerate into a point.
Rectangles and points may overlap, that is, there is no guarantee that the figures are distinct.
After each query, you need to print the number of pairs of rectangles and points in which the point lies on the border or inside the rectangle.
Input
The first line contains one integer (), the number of queries.
Each of the following lines contains one query:
<1 x y>() — add a point with the coordinates to the plane.<2 x1 y1 x2 y2>(, ) — add a rectangle whose lower left corner has the coordinates and whose upper right corner has the coordinates .
Output
Print lines. The -th line must contain one integer, the number of pairs of rectangles and points in which the point lies on the side or inside the rectangle.
Notes
Explanation of the first example:
After the first query, we have one point with the coordinates and no rectangles at all, so there are no pairs of points and rectangles.
After the second query, we still have no rectangles, so there are no pairs.
There are still no rectangles after the third query.
In the fourth query, we added a rectangle whose lower left point has the coordinates and whose upper right corner has the coordinates . All three points added earlier lie inside this rectangle, so we have three pairs.
After the fifth query, we have four pairs: the points added during the first three queries lie inside the rectangle added in the fourth query (the first three pairs), and the point added in the second query lies inside the rectangle added in the fifth query (the fourth pair).