#abc251g. [abc251_g]Intersection of Polygons

[abc251_g]Intersection of Polygons

Problem Statement

The vertices of a convex NN-gon PP in an xyxy-plane are given as (x1,y1),(x2,y2),ldots,(xN,yN)(x_1, y_1), (x_2, y_2), \\ldots, (x_N, y_N) in the counterclockwise order. (Here, the positive direction of the xx-axis is right, and the positive direction of the yy-axis is up.)

Based on this polygon PP, we consider MM convex NN-gons P1,P2,ldots,PMP_1, P_2, \\ldots, P_M.
For i=1,2,ldots,Mi = 1, 2, \\ldots, M, the polygon PiP_i is obtained by shifting PP in the positive direction of the xx-axis by uiu_i and in the positive direction of the yy-axis by viv_i. In other words, PiP_i is a convex NN-gon whose vertices are $(x_1+u_i, y_1+v_i), (x_2+u_i, y_2+v_i), \\ldots, (x_N+u_i, y_N+v_i)$.

For each of QQ points (a1,b1),(a2,b2),ldots,(aQ,bQ)(a_1, b_1), (a_2, b_2), \\ldots, (a_Q, b_Q), determine if "the point is contained in all of the MM polygons P1,P2,ldots,PMP_1, P_2, \\ldots, P_M."

Here, we regard a point is also contained in a polygon if the point is on the polygon's boundary.

Constraints

  • 3leqNleq503 \\leq N \\leq 50
  • 1leqMleq2times1051 \\leq M \\leq 2 \\times 10^5
  • 1leqQleq2times1051 \\leq Q \\leq 2 \\times 10^5
  • \-108leqxi,yileq108\-10^8 \\leq x_i, y_i \\leq 10^8
  • \-108lequi,vileq108\-10^8 \\leq u_i, v_i \\leq 10^8
  • \-108leqai,bileq108\-10^8 \\leq a_i, b_i \\leq 10^8
  • All values in input are integers.
  • (x1,y1),(x2,y2),ldots,(xN,yN)(x_1, y_1), (x_2, y_2), \\ldots, (x_N, y_N) forms a convex NN-gon in the counterclockwise order.
  • Each interior angle of the polygon PP is less than 180180 degrees.

Input

Input is given from Standard Input in the following format:

NN x1x_1 y1y_1 x2x_2 y2y_2 vdots\\vdots xNx_N yNy_N MM u1u_1 v1v_1 u2u_2 v2v_2 vdots\\vdots uMu_M vMv_M QQ a1a_1 b1b_1 a2a_2 b2b_2 vdots\\vdots aQa_Q bQb_Q

Output

Print QQ lines. For i=1,2,ldots,Qi = 1, 2, \\ldots, Q, the ii-th line should contain Yes if point (ai,bi)(a_i, b_i) is contained in all of the MM polygons P1,P2,ldots,PMP_1, P_2, \\ldots, P_M; it should contain No otherwise.


Sample Input 1

5
-2 -3
0 -2
1 0
0 2
-2 1
2
0 1
1 0
6
0 0
1 0
0 1
1 1
-1 -1
-1 -2

Sample Output 1

Yes
No
Yes
Yes
Yes
No

Polygon PP is a pentagon (55-gon) whose vertices are (2,3),(0,2),(1,0),(0,2),(2,1)(-2, -3), (0, -2), (1, 0), (0, 2), (-2, 1).

  • Polygon P1P_1 is a pentagon (55-gon) obtained by shifting PP in the positive direction of the xx-axis by 00 and in the positive direction of the yy-axis by 11, so its vertices are (2,2),(0,1),(1,1),(0,3),(2,2)(-2, -2), (0, -1), (1, 1), (0, 3), (-2, 2).
  • Polygon P2P_2 is a pentagon (55-gon) obtained by shifting PP in the positive direction of the xx-axis by 11 and in the positive direction of the yy-axis by 00, so its vertices are (1,3),(1,2),(2,0),(1,2),(1,1)(-1, -3), (1, -2), (2, 0), (1, 2), (-1, 1).

Thus, the following 66 lines should be printed.

  • The 11-st line should be Yes because (a1,b1)=(0,0)(a_1, b_1) = (0, 0) is contained in both P1P_1 and P2P_2.
  • The 22-nd line should be No because (a2,b2)=(1,0)(a_2, b_2) = (1, 0) is contained in P2P_2 but not in P1P_1.
  • The 33-rd line should be Yes because (a3,b3)=(0,1)(a_3, b_3) = (0, 1) is contained in both P1P_1 and P2P_2.
  • The 44-th line should be Yes because (a4,b4)=(1,1)(a_4, b_4) = (1, 1) is contained in both P1P_1 and P2P_2.
  • The 55-th line should be Yes because (a5,b5)=(1,1)(a_5, b_5) = (-1, -1) is contained in both P1P_1 and P2P_2.
  • The 66-th line should be No because (a6,b6)=(1,2)(a_6, b_6) = (-1, -2) is contained in P2P_2 but not in P1P_1.

Note that a point on the boundary of a polygon is also considered to be contained in the polygon.


Sample Input 2

10
45 100
-60 98
-95 62
-95 28
-78 -41
-54 -92
-8 -99
87 -94
98 23
87 91
5
-57 -40
-21 -67
25 39
-30 25
39 -20
16
4 5
-34 -8
-63 53
78 84
19 -16
64 9
-13 7
13 53
-20 4
2 -7
3 18
-12 10
-69 -93
2 9
27 64
-92 -100

Sample Output 2

Yes
Yes
No
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
No