Half-plane land grab
Time limit2sMemory limit128 MB
Lines are added one at a time, and after each addition you must report the maximum y value over all added lines at a given x.
- Level
Hard8 of 10
- Topics
- Geometry, Dynamic programming, Binary search
- Solved
- No attempts yet
Problem
You play a land grab game on an infinite two-dimensional plane. Each turn you flick a stone, and the stone flies forever along the line . That line cuts the plane into two parts, and you capture the whole part that contains , meaning everything below the line.
Land you have captured stays captured. The land you hold at any moment is therefore the union of the lower half-planes of every line flicked so far.
Between flicks you want to know how high your captured land reaches at a given x coordinate. The flicks and the questions are given in chronological order. Answer every question.
Input
The first line contains the number of records (). Each of the next lines contains one record, in chronological order.
- A record
1 a bmeans a stone was flicked along the line (, ). - A record
2 xasks for the highest y coordinate of a captured point whose x coordinate is , using only the flicks made so far ().
The first record always starts with 1. Every input value is an integer.
Output
For each record starting with 2, print its answer on its own line, in the order the questions appear. Every answer is an integer.