Simple Polygons
Practice
5 (2 votes)
Geometry
Line sweep technique
Math
Medium
Problem
61% Success 1564 Attempts 50 Points 4s Time Limit 512MB Memory 1024 KB Max Code

Given n simple polygons, no two polygons has common points but one polygon can strictly be inside the other. You are asked to answer q queries of two kinds:

1 x y: add a point at position (x, y).

2 u: output the number of points inside or on boundary of u-th polygon.

Input Format

The first line of input contains a single integer T, denoting the number of test cases.

Each test case is described as follow: a single line contains an integer n, denoting the number of polygons, each polygon begins with an integer k, denoting the number of vertices, each of k following lines contains two space-seperated integers x y, denoting coordinates of its vertices. The next line contains an integer q, denoting the number of queries. Each queries is described as above.

Output Format

For each query, output a single line contains the answer.

Constraints

  • 1 ≤ T ≤ 5
  • 1 ≤ n, q ≤ 105
  • 1 ≤ sum of vertices of all polygons overall test cases ≤ 106
  • 0 ≤ all coordinates ≤ 108
  • 1 ≤ u ≤ n

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
48 votes
Tags:
GeometryImplementationAd-HocEasy-MediumMathematicsOpenApproved