#P7727. [2019年杭电多校]Intersection of Prisms
[2019年杭电多校]Intersection of Prisms
Intersection of Prisms
Problem Description
Cuber QQ used to encounter such a problem: find the intersection of two infinitely long convex right prisms and . Actually this problem is also on HDU Online Judge, you can solve it afterwards if you are interested. Cuber QQ quickly solved it, and thought it too easy because his program can handle more than that. So he modify it a little bit, by removing the constraints of ``convex'', that is, the cross-section of these two prisms are not necessarily convex, but they are still simple. Formally, you have to find the volume of intersection of two prisms, whose cross-sections are both simple polygons. All joining edges of are parallel to the -axis, and all joining edges of are parallel to the -axis. If A and B do not intersect, the answer is of course.
Input
The first line is an integer , denoting the number of test cases follows. For each test case, there are two polygons, the base polygon of and respectively. An integer () followed by lines, each containing two space-separated integers (), is the representation of the base polygon of . The following () gives a similar representation for , except that the coordinates given are (). Each polygon are given in either clockwise or counterclockwise order. Following the convention, polygon is simple, if no two edges have any points in common, with the obvious exception of two consecutive segments having one common point. The sum of from all test cases does not exceed .
Output
For each test case, output the answer modulo , that is, if the answer is , you should output modulo , where denotes the multiplicative inverse of modulo .
Sample Input
1
4
10 0
0 10
-10 0
0 -10
3
5 0
-15 -10
-15 10
Sample Output
666667713
Hint
The intersection of the sample input is 3125/3. Prisms before intersection:
The intersection part looks like this: The input size is quite large. Please mind the efficiency of your input buffer.
Source
2019 Multi-University Training Contest 7