#P15504. [ICPC 2025 APC] Can You Reach There?

[ICPC 2025 APC] Can You Reach There?

Description

You are given nn distinct marked points on a 2D plane, numbered from 11 to nn. Marked point ii has coordinates (xi,yi)(x_i, y_i). In this problem, you are given qq scenarios, numbered from 11 to qq. In each scenario kk, four integers aka_k, bkb_k, ckc_k, and dkd_k are given, indicating that you initially stand at (ak,bk)(a_k, b_k) and aim to reach (ck,dk)(c_k, d_k) by repeating the steps described below any number of times.

In a single step, you choose two marked points PP and QQ, which may be identical. Let SS denote the point where you are currently standing, and define a point TT by

PT=SQ\overrightarrow{PT} = \overrightarrow{SQ}

In other words, TT is chosen so that the vector from PP to TT has the same direction and length as the vector from SS to QQ. You may then move to any point on the segment STST, including the point TT itself, and you will stand at that new point.

For each scenario, determine whether the objective can be achieved using the described steps. Note that all scenarios are independent of each other.

Input Format

The first line of input contains two integers nn and qq (1n1000001 \leq n \leq 100\,000, 1q1000001 \leq q \leq 100\,000). The ii-th of the next nn lines contains two integers xix_i and yiy_i (0xi,yi1090 \leq x_i, y_i \leq 10^9). The input guarantees that no two marked points have the same coordinates.

The next qq lines represent the scenarios. The kk-th of these lines contains four integers aka_k, bkb_k, ckc_k, and dkd_k (0ak,bk,ck,dk1090 \leq a_k, b_k, c_k, d_k \leq 10^9; (ak,bk)(ck,dk)(a_k, b_k) \neq (c_k, d_k)).

Output Format

Output qq lines. The kk-th line should contain yes if the objective of scenario kk is achievable, or no otherwise.

2 4
10 0
0 10
3 4 6 5
4 0 7 0
4 0 16 0
123 456 789 0
yes
yes
yes
no

Hint

Explanation for the sample input/output #1

There are two marked points (10,0)(10, 0) and (0,10)(0, 10). In scenario 1, starting from the point S=(a1,b1)=(3,4)S = (a_1, b_1) = (3, 4), the objective is achieved as follows:

  • In the first step, choose (10,0)(10, 0) as PP and (0,10)(0, 10) as QQ. A point TT is determined with coordinates (7,6)(7, 6). Move to a point (40/7,75/14)(40/7, 75/14), which lies on the segment STST. (Figure M.1 (a))
  • In the next step, choose (10,0)(10,0) as both PP and QQ. A point TT is determined with coordinates (100/7,75/14)(100/7, -75/14). From there, you can reach the point (c1,d1)=(6,5)(c_1, d_1) = (6, 5). (Figure M.1 (b))

In scenario 2, you start from S=(a2,b2)=(4,0)S = (a_2, b_2) = (4, 0). Choose (10,0)(10,0) as both PP and QQ. A point TT is determined with coordinates (16,0)(16, 0). The point (c2,d2)=(7,0)(c_2, d_2) = (7, 0) is on the segment STST, allowing you to reach there in a single step. (Figure M.1 (c))

In scenario 3, the objective is similarly achievable.

In scenario 4, it can be shown that reaching the point (c4,d4)=(789,0)(c_4, d_4) = (789, 0) from (a4,b4)=(123,456)(a_4, b_4) = (123, 456) is impossible.

:::align{center}

Figure M.1: Illustrations of the scenarios in Sample Input #1. :::