#P7138. [THUPC 2021 初赛] 非欧几何

[THUPC 2021 初赛] 非欧几何

Description

ustze likes geometry. He believes geometry is the easiest part of math contests. After conquering mathematics, ustze decided to bring his talent into computational geometry and compete with traditional Euclidean geometry.

As a defender of Euclidean geometry, Tinytree builds in 3D space a sphere with center at the origin and radius R\boldsymbol R. The point with coordinates (0,0,R)(0,0,R) is called the North Pole, and obviously it lies on the sphere. Tinytree recalls that in Euclidean geometry, three points can uniquely determine a circle in space. Therefore, Tinytree chooses NN pairs of points on the sphere. For each pair, together with the North Pole, they determine a circle on the sphere. We guarantee that the radius of each such circle is strictly less than R\boldsymbol R. Hence each circle divides the sphere into two parts of unequal area. We call the part with smaller area the interior of the circle, and the part with larger area the exterior of the circle. The interiors of these NN circles are protected by Tinytree, and their union forms the safe region.

As a fanatic of non-Euclidean geometry, ustze thinks that circles on a sphere are actually “straight lines”. He chooses MM pairs of points on the sphere. For each pair, together with the North Pole, they also determine a circle on the sphere. The radii of these circles are also strictly less than R\boldsymbol R. The interiors of these MM circles are under ustze’s intimidation, and their union forms the dangerous region.

While Tinytree and ustze are confronting each other, a passerby named Kiana happens to be on the sphere. She is frightened by what she sees and starts to hide and move around on the sphere. Now Kiana has preliminarily chosen TT points on the sphere. She wants to know whether these points are in the safe region or the dangerous region so that she can decide where to run. Since Kiana cannot compute it herself, she hopes you can help her.

Input Format

The first line contains three positive integers N,MN, M and TT (1N,M50001 \le N, M \le 5000, 1T1.5×1051 \le T \le 1.5 \times {10}^5), representing the number of point pairs chosen by Tinytree, the number of point pairs chosen by ustze, and the number of escape points chosen by Kiana.

The second line contains a positive integer RR (1R1031 \le R \le {10}^3), representing the radius of the sphere.

The next NN lines: the ii-th line contains Ai,Bi,Xi,Ci,Di,YiA_i, B_i, X_i, C_i, D_i, Y_i (1Ai,Bi,Ci,DiR1 \le |A_i|, |B_i|, |C_i|, |D_i| \le R, 1Ai2+Bi2,Ci2+Di2R21 \le A_i^2 + B_i^2, C_i^2 + D_i^2 \le R^2). Here, Ai,BiA_i, B_i are the xx- and yy-coordinates of the first point in Tinytree’s ii-th pair, and XiX_i is + meaning the zz-coordinate of the first point is greater than 00, and - meaning the zz-coordinate is less than 00. If the zz-coordinate equals 00, then XiX_i is chosen randomly between + and -. Similarly, Ci,DiC_i, D_i are the xx- and yy-coordinates of the second point in the pair, and YiY_i indicates the sign of its zz-coordinate, with the same meaning as XiX_i.

The next MM lines: the jj-th line contains Aj,Bj,Xj,Cj,Dj,YjA_j, B_j, X_j, C_j, D_j, Y_j (1Aj,Bj,Cj,DjR1 \le |A_j|, |B_j|, |C_j|, |D_j| \le R, 1Aj2+Bj2,Cj2+Dj2R21 \le A_j^2 + B_j^2, C_j^2 + D_j^2 \le R^2), representing the coordinates of ustze’s jj-th point pair. The representation of points is the same as above.

The next TT lines: the kk-th line contains two real numbers Ak,BkA_k, B_k (1Ak,BkR1 \le |A_k|, |B_k| \le R, 1Ak2+Bk2R21 \le A_k^2 + B_k^2 \le R^2) and a character XkX_k, representing Kiana’s kk-th escape point. The representation of points is the same as above.

The testdata guarantees validity, and there are no two identical points in the input. All real numbers are given to three digits after the decimal point. The minimum straight-line distance between any of Kiana’s escape points and the circumference of any given circle is at least 106\boldsymbol{{10}^{-6}}.

Output Format

Output TT lines. Each line contains a string. If Kiana’s kk-th escape point is in the safe region, output Safe on the kk-th line. If it is not in the safe region and also not in the dangerous region, output Passer on the kk-th line. If it is not in the safe region but is in the dangerous region, output Goodbye (all outputs are without quotes).

2 2 4
3
2.571 0.514 + 2.571 -0.514 +
-2.571 0.514 + -2.571 -0.514 +
0.514 2.571 + -0.514 2.571 +
0.514 -2.571 + -0.514 -2.571 +
2.118 -2.118 -
1.051 1.051 +
-0.468 1.870 +
-1.870 -0.468 +

Passer
Safe
Goodbye
Safe

Hint

In 3D space, we can use an ordered real triple (x,y,z)(x, y, z) to describe the position of a point, where x,y,zx, y, z are called the xx-coordinate, yy-coordinate, and zz-coordinate of the point.

A sphere in 3D space with center at (x0,y0,z0)(x_0, y_0, z_0) and radius RR refers to the set of all points (x,y,z)(x, y, z) satisfying (xx0)2+(yy0)2+(zz0)2=R2(x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 = R^2. For two different points (x1,y1,z1),(x2,y2,z2)(x_1, y_1, z_1), (x_2, y_2, z_2) on this sphere, if they are not a pair of antipodal points (two points are antipodal if and only if the distance between them is 2R2 R), then these two points and the center are not on the same line. These three points uniquely determine a plane. The intersection of this plane with the sphere is divided by the two points into two parts, and the length of the shorter part is called the distance between the two points on the sphere. If the two points are antipodal, then their distance is defined as πR\pi R. A circle on a sphere refers to the set of points on the sphere whose spherical distance to some point on the sphere equals a constant. It can be proven that any three different points on the sphere uniquely determine a circle on the sphere.

[Source]

From the preliminary round of the 2021 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2021).

Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2021-pre.

Translated by ChatGPT 5