Flights
Time limit3sMemory limit1024 MB
For each query, find the maximum altitude among a subset of parabolic missile trajectories (indexed by launch time) restricted to a horizontal range, and output the exact reduced fraction.
- Level
Hard8 of 10
- Topics
- Geometry, Segment tree, Math, Binary search
- Solved
- No attempts yet
Statement
The battlefield is a straight line. Artillery launches ballistic missiles and aviation plans flights over the same line; you must compute the minimal safe altitude for every flight.
A ballistic missile is launched from the ground (altitude ) at a point and flies along a vertically symmetric parabola whose highest point is : its horizontal coordinate is and its peak altitude is . At a horizontal coordinate the missile altitude is
and the missile exists only along the arc above the ground, i.e. for ; outside that range it has no trajectory.
Missiles are launched one per minute in input order, so missile is launched at minute . A flight is given by a time interval and a space interval (both inclusive). Its minimal safe altitude is the smallest altitude at or below which every missile launched during stays throughout the horizontal range . Equivalently, it is the maximum altitude reached by any such missile over , counting only the part of each trajectory that is above the ground. If no such missile reaches any point of , the minimal safe altitude is .
Input
The first line contains one integer — the number of planned missile launches ().
Each of the next lines contains three integers , , describing one launch: the launch point and the highest point of the trajectory (, ). Missiles are launched one by one every minute in the order given; launch happens at minute .
The next line contains one integer — the number of planned flights ().
Each of the next lines contains four integers , , , : the time interval () and the space interval (). Both intervals include their endpoints. Minute is the first launch and minute is the last.
Output
For each flight, print on its own line the minimal safe altitude as an exact irreducible fraction p/q, where and . The altitude is always a non-negative rational number, so ; print a zero altitude as 0/1.