Ghost
Time limit10sMemory limit512 MB
Given axis-aligned rectangles that move at constant speeds, answer each query by reporting the maximum area common to all rectangles during a time interval [l, r].
- Level
Hard9 of 10
- Topics
- Geometry, Sorting, Binary search
- Solved
- No attempts yet
Problem
Your team has been trapped in an ancient chamber at Wawel Castle in Kraków by the Ghost. He will not let you out unless you answer his questions.
On the wall there are paintings. If we treat the wall as the standard Euclidean plane, each painting is an axis-aligned rectangle. For every painting you know its exact dimensions and starting position. At moment 0, the Ghost starts moving the paintings, each one in its own direction and speed. You are an observant team, so you can work out the exact speed of every painting.
After some time, the Ghost stops the show and starts asking tough questions. Each question gives two numbers and , which are moments of the show. You must tell the Ghost whether there was a moment between and when some spot on the wall was covered by all the paintings at once. If so, you must also find the maximum possible common area of all paintings between moments and .
If you ever want to leave this room, give the Ghost the right answers.
Input
The first line contains the number of test cases (). Each test case has the following format.
The first line of a test case contains the number of paintings (). Each of the next lines contains six numbers (; ; ), where is the lower left corner of the painting, is its upper right corner, and is its speed vector. At moment , the lower left corner is at and the upper right corner is at .
The next line contains the number of Ghost's questions (). Each of the next lines contains two real numbers and () with at most 4 decimal places, which denote the closed time interval .
The total number of paintings across all test cases does not exceed 1000000. The total number of questions across all test cases does not exceed 1000000.
Output
For each question, print one real number: the maximum area of the intersection of all paintings during the interval . Your answer is accepted if the absolute or relative error is at most . That is, if your output is and the correct value is , it is accepted when . If the intersection is empty, print 0 (an error of is allowed).