Candles and Shadows
Time limit1sMemory limit512 MB
Given a convex red polygon that contains a convex blue polygon, find the shadow area cast by the blue polygon for each candle position.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Math
- Solved
- No attempts yet
Problem
A red convex polygon with vertices and a blue convex polygon with vertices are given. As the figure shows, the blue polygon lies completely inside the red polygon.

Figure 1. A red polygon containing a blue polygon
Let be the region inside the red polygon that is not inside or on the boundary of the blue polygon. As the figure shows, placing a candle at a point of lights the yellow region, and the gray region casts a shadow.

Figure 2. The lit region and the shadow region
Given the polygons and the position of the candle, write a program that computes the area of the shadow region.
Input
The first line contains three positive integers , , and , separated by spaces. They are the number of vertices of the red polygon, the number of vertices of the blue polygon, and the number of queries.
The next lines give the vertices of the red polygon in counterclockwise order. Line contains two integers and separated by a space ().
Starting from line , the next lines give the vertices of the blue polygon in counterclockwise order. Line contains two integers and separated by a space ().
Starting from line , the next lines describe the queries. Line contains two integers and , meaning that in the -th query the candle is placed at . All queries are independent of each other.
Output
Print the answer to each query on its own line, in order.
If the candle is outside the red polygon or on its boundary, print OUT.
If the candle is inside the blue polygon or on its boundary, print IN.
Otherwise, print the area of the shadow region. An absolute or relative error up to is allowed.
Constraints
All input data satisfy the following conditions.
- ()
- ()
- ()
- ()
- ()
- ()