Architect
Time limit1sMemory limit64 MB
Given N tree points and Q axis-aligned polygons of at most 12 vertices, count for each polygon how many trees lie inside it, border included.
- Level
Medium6 of 10
- Topics
- Geometry, Array, Brute force, Implementation
- Solved
- No attempts yet
Problem
Matija has a job at a company that builds houses. Every day clients send him orders: they want to build on a particular parcel of land, and Matija has to cut down every tree standing on it. Once all the orders are in, he first has to work out, for each parcel, how many trees are inside it right now, before anything is cut. A tree on the border of a parcel counts as inside it.
You are given the position of every tree in the plane and a description of the parcels the clients are interested in. The size of a single tree is negligible. Each parcel is a polygon with vertices, and every edge is either horizontal or vertical. The edges of one parcel never meet each other, while two different parcels may overlap.
Input
The first line has the number of trees in the plane, (). Each of the next lines has two integers , , the coordinates of one tree (). No two trees share the same coordinates.
The next line has the number of client orders, (). After it come lines that describe the orders. Each order takes two lines. The first line has the number of vertices of the polygon describing the parcel (), and the second line has integers listing the coordinates of that parcel's vertices in order, in pairs. Parcel vertex coordinates are also at most in absolute value.
The vertices are given in counterclockwise order. For every pair of adjacent edges, one is horizontal and the other is vertical.
Output
Print lines. For each client order print one line holding the number of trees on the matching parcel. Line of the output must correspond to order of the input.