Patrol
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
Special Judge, 64bit IO Format: %lld

题目描述

A castle can be regarded as a convex polygon with n vertices on the plane, whose vertices are p_1, p_2, \ldots, p_n in counterclockwise order.

The king sent q soldiers to patrol outside the castle. The patrol route of the i-th soldier is a line segment from (a_i, b_i) to (c_i, d_i) that lies strictly outside the castle. Each soldier carries a lantern that can be regarded as a point light source, and once the light touches the boundary of the castle, it will no longer propagate any further (and no reflection or similar phenomenon occurs).

To evaluate the patrol strength, the king wants to know: during the patrol, what is the total length of the castle boundary that each soldier can see with the help of the lantern?

输入描述:

The first line contains a positive integer T (1 \le T \le 10^4), denoting the number of test cases.

For each test case, the first line contains two positive integers n, q (3 \le n \le 10^5, 1 \le q \le 10^5), denoting the number of vertices of the convex polygon and the number of soldiers.

The next n lines give the vertices of the castle's convex polygon in counterclockwise order. The i-th line contains two integers x_i, y_i (|x_i|, |y_i| \le 10^9), denoting the coordinates of vertex p_i. It is guaranteed that no three of these n points are collinear.

The next q lines each contain four integers a_i, b_i, c_i, d_i (|a_i|, |b_i|, |c_i|, |d_i| \le 10^9), denoting the patrol route of the i-th soldier. It is guaranteed that the patrol route lies strictly outside the castle and does not intersect the castle boundary. Be aware that (a_i, b_i) and (c_i, d_i) may be the same.

For all test cases, it is guaranteed that the sum of n and the sum of q do not exceed 10^5.

输出描述:

For each soldier in each test case, output one real number per line, representing the total length of the castle boundary that the soldier can see with the help of the lantern. Your output will be accepted if the absolute or relative error between your output and the answer does not exceed 10^{-9}.
示例1

输入

复制
2
4 4
0 0
10 0
10 10
0 10
2 -5 8 -5
15 -5 20 -5
-5 -5 15 -5
-5 5 5 16
3 3
0 0
12 0
0 5
-2 -2 14 -2
6 6 14 6
-5 6 15 6

输出

复制
10.0000000000
20.0000000000
30.0000000000
20.0000000000
17.0000000000
13.0000000000
18.0000000000

备注:

The figure shows the castle boundary as seen by the first soldier, which is marked as red, in the first test case.