This page is still under construction.

Parts of this page are still being built. What you see may change.

Mountain View

Time limit2sMemory limit512 MB

Summary
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.

NN

c1c_1 r1r_1

⋮\vdots

cNc_N rNr_N

QQ

x1x_1

⋮\vdots

xQx_Q

The first line contains a single integer NN (1≤N≤1051 \le N \le 10^5), where NN is the number of mountains of the Alps of Curved Mountains. The ii-th of the following NN lines contains two integers cic_i (1≤ci≤1081 \le c_i \le 10^8) and rir_i (1≤ri≤1081 \le r_i \le 10^8). cic_i is the position of the center of the ii-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. rir_i is the radius of the ii-th semicircle. The following line contains a single integer QQ (1≤Q≤1051 \le Q \le 10^5), where QQ is the number of the positions on a straight line Mr. Mt. is interested in. The jj-th of the following QQ lines contains a single integer xjx_j (1≤xj≤1081 \le x_j \le 10^8), where xjx_j is the jj-th position on a straight line Mr. Mt. is interested in.

Output

Output QQ lines, the jj-th of which is the height of the shadow of the mountains at the jj-th position Mr. Mt. is interested in. Absolute or relative errors less than 10−710^{-7} are permissible.

Examples3

  1. Example 1

    Input
    3
    1 10
    4 10
    10 5
    6
    4
    2
    8
    12
    14
    18
    
    Expected output
    10.0000000000
    9.9498743711
    9.1651513899
    6.0000000000
    3.0000000000
    0.0000000000
    
  2. Example 2

    Input
    5
    23 10
    32 7
    41 10
    75 12
    79 6
    6
    10
    32
    36
    60
    75
    82
    
    Expected output
    0.0000000000
    7.0000000000
    8.6602540378
    0.0000000000
    12.0000000000
    9.7467943448
    
  3. Example 3

    Input
    9
    3 8
    21 10
    12 9
    15 3
    1 11
    19 4
    9 6
    17 1
    22 7
    7
    19
    3
    16
    8
    9
    31
    1
    
    Expected output
    9.7979589711
    10.8166538264
    8.6602540378
    8.4852813742
    8.4852813742
    0.0000000000
    11.0000000000