Low Budget Inception
Contest: Educational Codeforces Round 65 (Rated for Div. 2)
Difficulty rating: 3100
Tags: brute force, geometry

So we got bored and decided to take our own guess at how would "Inception" production go if the budget for the film had been terribly low.

The first scene we remembered was the one that features the whole city bending onto itself:

It feels like it will require high CGI expenses, doesn't it? Luckily, we came up with a similar-looking scene which was a tiny bit cheaper to make.

Firstly, forget about 3D, that's hard and expensive! The city is now represented as a number line (infinite to make it easier, of course).

Secondly, the city doesn't have to look natural at all. There are $$$n$$$ buildings on the line. Each building is a square $$$1 \times 1$$$. Buildings are numbered from $$$1$$$ to $$$n$$$ in ascending order of their positions. Lower corners of building $$$i$$$ are at integer points $$$a_i$$$ and $$$a_i + 1$$$ of the number line. Also the distance between any two neighbouring buildings $$$i$$$ and $$$i + 1$$$ doesn't exceed $$$d$$$ (really, this condition is here just to make the city look not that sparse). Distance between some neighbouring buildings $$$i$$$ and $$$i + 1$$$ is calculated from the lower right corner of building $$$i$$$ to the lower left corner of building $$$i + 1$$$.

Finally, curvature of the bend is also really hard to simulate! Let the bend at some integer coordinate $$$x$$$ be performed with the following algorithm. Take the ray from $$$x$$$ to $$$+\infty$$$ and all the buildings which are on this ray and start turning the ray and the buildings counter-clockwise around point $$$x$$$. At some angle some building will touch either another building or a part of the line. You have to stop bending there (implementing buildings crushing is also not worth its money).

Let's call the angle between two rays in the final state the terminal angle $$$\alpha_x$$$.

The only thing left is to decide what integer point $$$x$$$ is the best to start bending around. Fortunately, we've already chosen $$$m$$$ candidates to perform the bending.

So, can you please help us to calculate terminal angle $$$\alpha_x$$$ for each bend $$$x$$$ from our list of candidates?

Input format:
The first line contains two integer numbers $$$n$$$ and $$$d$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le d \le 7000$$$) — the number of buildings and the maximum distance between any pair of neighbouring buildings, respectively.

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_1 = 0$$$, $$$0 < a_{i + 1} - a_i \le d + 1$$$) — coordinates of left corners of corresponding buildings in ascending order.

The third line contains single integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of candidates.

The fourth line contains $$$m$$$ integers $$$x_1, x_2, \dots, x_m$$$ ($$$0 \le x_i \le a_n + 1$$$, $$$x_i < x_{i + 1}$$$) — the coordinates of bends you need to calculate terminal angles for in ascending order.

Output format:
Print $$$m$$$ numbers. For each bend $$$x_i$$$ print terminal angle $$$\alpha_{x_i}$$$ (in radians).

Your answer is considered correct if its absolute error does not exceed $$$10^{-9}$$$.

Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$|a - b| \le 10^{-9}$$$.

Constraints:
Time limit: 3.0 s
Memory limit: 256.0 MB

Note:
Here you can see the picture of the city for the first example and the bend at position $$$2$$$ for it. The angle you need to measure is marked blue. You can see that it's equal to $$$\frac \pi 4$$$.

You can see that no pair of neighbouring buildings have distance more than $$$4$$$ between them. $$$d = 4$$$ would also suffice for that test.

Example input:
3 5
0 5 7
9
0 1 2 3 4 5 6 7 8

Example output:
1.570796326794897
1.570796326794897
0.785398163397448
0.927295218001612
0.785398163397448
1.570796326794897
1.570796326794897
1.570796326794897
1.570796326794897

Example input:
2 7
0 4
3
1 3 4

Example output:
1.570796326794897
0.927295218001612
1.570796326794897

Editorial:
Let's solve the problem for a single query at first. There are two possible types of collisions: between two buildings and between a building and a ray.
Obviously, if the collision of the second type happens, then it's the building which is the closest to the bend point (from either left or right).
The less obvious claim is that among all buildings collisions, the closest is the biggest angle one. Let's boil down some possibilities of colliding buildings. Let two buildings be the same distance $$$D$$$ from the bend point $$$x$$$. Then they will collide and the collision point will $$$(x - D, 1)$$$. Two buildings also collide if the left one is $$$D + 1$$$ from $$$x$$$ and the right one is $$$D$$$. Then the point of collision is $$$(x - D + 1, 1)$$$. And for the opposite case the point of collision is also $$$(x - D + 1, 1)$$$. These points can be easily proven by checking the distances to upper corners of each building. No other two buildings will collide.
Now that we know this, we can transition to solving a problem of checking if there exists such a pair that the distances to $$$x$$$ from them differ by at most one. Finding such a pair with minimal $$$D$$$ is enough. Obviously, this can be done with some sort of two pointers. However, that's not the intended solution.
Let's constuct bitset of 7000 positions to the left of the bend and to the right of the bend. AND of these bitsets will give you the pairs such that the distance $$$D$$$ is the same for them. However, you can put 1 in points $$$y - 1$$$ and $$$y$$$ for each building to the left and $$$y$$$ and $$$y + 1$$$ for each building to the right. This way AND will give you the exact pairs you need. Use _Find_first to find the closest one.
Let collision happen on distance $$$D$$$. Then the collision of the first type will have angle $$$2 \cdot arctan D$$$ and the collision of the second type will have angle $$$arctan D$$$. The answer is the maximum of these two values. Be careful with cases where $$$D = 0$$$.
How to process lots of queries. Let's just move the bitsets to the right while going through queries in ascending order. Bitsets can be updated in $$$(d / 32)$$$ for each query and only $$$n$$$ buildings will be added to them in total.
Overall complexity: $$$O(md / 32 + n)$$$.