Mountain View
Time limit2sMemory limit512 MB
Given N semicircles on a line, each centered at c_i with radius r_i, answer Q queries asking the maximum height among semicircles covering a given x.
- Level
Medium6 of 10
- Topics
- Geometry, Sorting, Binary search, Array
- Solved
- No attempts yet
Problem
Mr. Mt. is eager to take photos of mountains all over the world. Today, Mr. Mt. visits one of the most interesting mountain ranges, the Alps of Curved Mountains. The shape of all the mountains of the Alps of Curved Mountains is, surprisingly, a hemisphere.
Mr. Mt. has just decided the place from where he will take photos of the mountains. The area covering the mountains is flat, horizontal ground, and the place he chose is far enough from the mountains. Hence the mountains look like two-dimensional semicircles in a row, where all the straight segments of the semicircles are aligned with a straight line. Some of them may be overlapped or completely covered by other semicircles.
Mr. Mt. is waiting for the sunset. After sunset, the mountains are in shadow and cannot be distinguished. In that situation, Mr. Mt. is interested in how the photos will look like. You, his camera assistant, are also a great programmer. Given the coordinates and radiuses of all the semicircles, he asks you to write a program to calculate the heights of the 2D shadow at the positions he wants to know.
Figure F-1 illustrates the mountains of Sample 2. The first, second, third mountains are overlapped, and the fifth mountain is covered by the fourth mountain. Figure F-2 shows the mountains in shadow. For example, at position 82, there are the fourth and fifth mountains, and the shadow's height is the highest of them, the height of the fourth mountain.

Figure F-1. Mountains of Sample 2

Figure F-2. Mountains in shadow and positions of Sample 2
Input
The input consists of a single test case in the format below.
The first line contains a single integer (), where is the number of mountains of the Alps of Curved Mountains. The -th of the following lines contains two integers () and (). is the position of the center of the -th semicircle in a straight line, where "center" means the center of the circle made by reflecting the semicircle on the straight segment of the semicircle. is the radius of the -th semicircle. The following line contains a single integer (), where is the number of the positions on a straight line Mr. Mt. is interested in. The -th of the following lines contains a single integer (), where is the -th position on a straight line Mr. Mt. is interested in.
Output
Output lines, the -th of which is the height of the shadow of the mountains at the -th position Mr. Mt. is interested in. Absolute or relative errors less than are permissible.