Pastries
Time limit1sMemory limit128 MB
Given up to 100,000 triangles with integer vertices and 100,000 axis-aligned lines, count for each line how many triangles it cuts into two positive-area pieces.
- Level
Medium7 of 10
- Topics
- Geometry, Binary search, Sorting, Implementation
- Solved
- No attempts yet
Problem
A bakery has baked triangular pastries. Every pastry can be described as a triangle whose three vertices have integer coordinates on the 2D plane.
A child wants to cut the pastries with a large knife. Each cut is made along a vertical line or a horizontal line . For a single cut, we want to know how many pastries in total get cut. A pastry is considered cut if the cut divides it into two parts and both parts have area greater than .
Given the positions of the pastries and the list of cuts, write a program that determines how many pastries each cut slices through.
Input
The first line contains the number of pastries . ()
Each of the next lines contains six non-negative integers, each smaller than . In order they are , , , the three vertices of a triangular pastry. No three of these points are collinear. Different pastries may overlap or touch each other.
The next line contains the number of cuts . ()
Each of the next lines describes one cut in the form x = c or y = c, where is a non-negative integer smaller than .
Output
Print, one per line and in the given order, how many pastries each cut slices through. Treat every cut independently; that is, assume the pastry magically becomes whole again after each cut.