F - Origami Warp Editorial /

Time Limit: 3 sec / Memory Limit: 1024 MiB

Score: 100 points

Problem Statement

You are given N lines on the xy-plane. The i-th line (1 \le i \le N) passes through two distinct points (a_i, b_i) and (c_i, d_i). Specifically, (a_1, b_1, c_1, d_1) = (0, 0, 1, 0) and (a_2, b_2, c_2, d_2) = (0, 0, 0, 1). That is, the first line represents the x-axis, and the second line represents the y-axis.

Alice is on the xy-plane. She can perform the following operation any number of times (including zero):

Choose one of the N given lines. Alice moves to the position symmetric to her current position with respect to the chosen line.

Additionally, we define that point P is reachable from point S if the following condition is satisfied:

For any real number \varepsilon > 0, there exists a point Q such that the Euclidean distance between Q and P is at most \varepsilon, and Alice can move from S to Q in a finite number of operations.

Answer Q queries. For the i-th query (1 \le i \le Q), you are given integers X_i, Y_i, Z_i, W_i. Output Yes if (Z_i, W_i) is reachable from (X_i, Y_i). Otherwise, output No.

Solve the problem for T test cases.

Constraints

  • All input values are integers.
  • 1 \le T \le 100
  • For each test case:
    • 2 \le N \le 2000
    • 1 \le Q \le 2000
    • -10^8 \le a_i, b_i, c_i, d_i \le 10^8 \ (1 \le i \le N)
    • (a_i, b_i) \neq (c_i, d_i)
    • (a_1, b_1, c_1, d_1) = (0, 0, 1, 0)
    • (a_2, b_2, c_2, d_2) = (0, 0, 0, 1)
    • All given lines are distinct.
    • -10^8 \le X_i, Y_i, Z_i, W_i \le 10^8 \ (1 \le i \le Q)

Input

The input is given from Standard Input in the following format:

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

Here, \text{case}_i represents the i-th test case. Each test case is given in the following format:

N
a_1 b_1 c_1 d_1
a_2 b_2 c_2 d_2
\vdots
a_N b_N c_N d_N
Q
X_1 Y_1 Z_1 W_1
X_2 Y_2 Z_2 W_2
\vdots
X_Q Y_Q Z_Q W_Q

Output

For each test case, output Q lines. The i-th line (1 \le i \le Q) should contain the answer to the i-th query.
The judge is case-insensitive for Yes and No.


Sample Input 1

2
3
0 0 1 0
0 0 0 1
0 2 2 0
4
1 0 2 3
1 -2 -1 2
1 1 -1 0
3 3 3 3
3
0 0 1 0
0 0 0 1
-2 1 2 3
2
2 1 -1 5
-1 -1 3 3

Sample Output 1

Yes
Yes
No
Yes
Yes
Yes

Let us explain the first test case. For the first query, Alice can use the second and third lines in sequence to move (1, 0) \to (-1, 0) \to (2, 3). Thus, (2, 3) is reachable from (1, 0). Note that for the fourth query, if (X_i, Y_i) = (Z_i, W_i), the destination is always reachable.

Now let us explain the second test case. For the first query, Alice can use the first and third lines in sequence to move (2, 1) \to (2, -1) \to \left(-\frac{6}{5}, \frac{27}{5}\right). The distance between (-1, 5) and \left(-\frac{6}{5}, \frac{27}{5}\right) is \frac{1}{\sqrt{5}}. This means that for \varepsilon \ge \frac{1}{\sqrt{5}}, Alice can find a point Q that satisfies the "reachable" condition. Moreover, for any \varepsilon > 0, Alice can find such a point Q. As a result, (2, 1) is reachable from (-1, 5).

配点 : 100

問題文

xy 平面上に N 本の直線が与えられます。i 本目 (1 \le i \le N) の直線は異なる 2(a_i,b_i),(c_i,d_i) を通る直線です。ただし、(a_1,b_1,c_1,d_1)=(0,0,1,0)(a_2,b_2,c_2,d_2)=(0,0,0,1) です。すなわち、1 本目の直線は x 軸を表しており、2 本目の直線は y 軸を表しています。

Alice が xy 平面上にいます。Alice は、以下の操作を 0 回以上好きな回数行うことができます。

与えられた N 本の直線のうち 1 つを選ぶ。Alice は、選んだ直線について現在位置と線対称な位置に移動する。

また、点 S から点 P到達可能であるということを、次のように定義します。

任意の実数 \varepsilon >0 について、P とのユークリッド距離が \varepsilon 以下であるような点 Q が存在して、Alice が S から Q に有限回の操作で移動できる。

Q 個のクエリに答えてください。 i 番目 (1 ≤ i ≤ Q) のクエリでは、整数 X_i,Y_i,Z_i,W_i が与えられるので、(X_i,Y_i) から (Z_i,W_i) に到達可能であるならば Yes を、そうでないならば No を出力してください。

T 個のテストケースについて解いてください。

制約

  • 入力はすべて整数
  • 1 \le T \le 100
  • 各テストケースについて:
    • 2 \le N \le 2000
    • 1 \le Q \le 2000
    • -10^8 \le a_i,b_i,c_i,d_i \le 10^8 \ (1 \le i \le N)
    • (a_i,b_i) \ne (c_i,d_i)
    • (a_1,b_1,c_1,d_1)=(0,0,1,0)
    • (a_2,b_2,c_2,d_2)=(0,0,0,1)
    • 与えられる直線はすべて異なる
    • -10^8 \le X_i,Y_i,Z_i,W_i \le 10^8 \ (1 \le i \le Q)

入力

入力は以下の形式で標準入力から与えられる。

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

ここで、\text{case}_ii 番目のテストケースを表す。各テストケースは以下の形式で与えられる。

N
a_1 b_1 c_1 d_1
a_2 b_2 c_2 d_2
\vdots
a_N b_N c_N d_N
Q
X_1 Y_1 Z_1 W_1
X_2 Y_2 Z_2 W_2
\vdots
X_Q Y_Q Z_Q W_Q

出力

各テストケースに対して、Q 行出力せよ。そのうち i 行目 (1 ≤ i ≤ Q) には、i 番目のクエリの答えを出力せよ。
なお、ジャッジは YesNo の大文字小文字を区別しない。


入力例 1

2
3
0 0 1 0
0 0 0 1
0 2 2 0
4
1 0 2 3
1 -2 -1 2
1 1 -1 0
3 3 3 3
3
0 0 1 0
0 0 0 1
-2 1 2 3
2
2 1 -1 5
-1 -1 3 3

出力例 1

Yes
Yes
No
Yes
Yes
Yes

最初のテストケースについて述べます。1 つ目のクエリについて、2 本目、3 本目の直線を順に使うことで、(1,0) \rightarrow (-1,0) \rightarrow (2,3) と移動することができるので、(1,0) から (2,3) は到達可能です。4 つ目のクエリについて、(X_i,Y_i)=(Z_i,W_i) であるときは常に到達可能なことに注意してください。

2 番目のテストケースについて述べます。1 つ目のクエリについて、1 本目、3 本目と順に使うと、(2,1) \rightarrow (2,-1) \rightarrow (-\frac{6}{5},\frac{27}{5}) と移動することができます。(-1,5)(-\frac{6}{5},\frac{27}{5}) の距離は \frac{1}{\sqrt{5}} なので、\varepsilon \ge \frac{1}{\sqrt{5}} に対しては、問題文中の到達可能の条件を満たすような Q として (-\frac{6}{5},\frac{27}{5}) をとることができます。同様に、任意の \varepsilon > 0 に対しても Q をとることができるため、(2,1) から (-1,5) は到達可能です。