#ABC472F. 切片重心 / Centroid of a Slice

切片重心 / Centroid of a Slice

Problem Statement

There is a convex NN-gon PP on the xyxy-plane. The vertices of PP are numbered 1,2,,N1,2,\dots,N counterclockwise, and the coordinates of vertex ii are (xi,yi)(x_i,y_i).

Answer QQ questions.

The jj-th question gives two distinct vertices uju_j and vjv_j. Here, the vertices uju_j and vjv_j are not adjacent on the boundary of PP.

The segment connecting vertices uju_j and vjv_j divides PP into two polygons; let PP' be the one lying to the right of the directed line from vertex uju_j to vertex vjv_j. Find the coordinates of the geometric center of PP' (the centroid obtained by regarding the interior of the polygon as a thin plate of uniform density).

Constraints

  • 4N3×1044 \leq N \leq 3 \times 10^4
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • xi,yi5×105|x_i|,|y_i| \leq 5 \times 10^5
  • (x1,y1),(x2,y2),,(xN,yN)(x_1,y_1),(x_2,y_2),\dots,(x_N,y_N) form a convex polygon in counterclockwise order.
  • All interior angles of PP are less than 180180 degrees.
  • 1uj,vjN1 \leq u_j,v_j \leq N
  • ujvju_j \neq v_j
  • Vertices uju_j and vjv_j are not adjacent on the boundary of PP.
  • All input values are integers.

Input

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

  • NN QQ
  • x1x_1 y1y_1
  • x2x_2 y2y_2
  • \vdots
  • xNx_N yNy_N
  • u1u_1 v1v_1
  • u2u_2 v2v_2
  • \vdots
  • uQu_Q vQv_Q

Output

Output QQ lines. On the jj-th line, letting (pj,qj)(p_j,q_j) be the coordinates of the answer to the jj-th question, output pjp_j and qjq_j in this order, separated by a space.

The answer is considered correct if, for each of pjp_j and qjq_j, its absolute or relative error from the true value is at most 10610^{-6}.

5 4
4 1
1 3
-3 2
-1 -2
2 -1
2 4
5 3
1 4
4 2
-1.000000000000000 1.000000000000000
0.864197530864198 1.209876543209877
0.198198198198198 0.828828828828829
1.391304347826087 0.434782608695652

For the first question, PP' is the triangle with vertices (1,3),(3,2),(1,2)(1,3),(-3,2),(-1,-2), and its geometric center is (1,1)(-1,1).

For the second question, PP' is the quadrilateral with vertices (2,1),(4,1),(1,3),(3,2)(2,-1),(4,1),(1,3),(-3,2), and its geometric center is (7081,9881)\left(\frac{70}{81},\frac{98}{81}\right).

10 10
480451 142016
404696 274257
7097 390813
-134582 195390
-167108 143104
-359470 -180367
-406293 -273476
74335 -494832
486873 -391664
493159 -292349
5 8
8 6
5 2
5 1
10 3
1 7
3 5
2 5
4 9
1 8
-167917.431926206833203 -207268.968943785114349
126221.026579795702381 -68771.715180365014040
111801.954824466955586 -124063.178438661167072
99590.935535112756283 -153792.378227918737825
321662.353363423237819 113722.100435559268610
43574.061369374611386 102411.022160871806300
-98197.666666666666667 243102.333333333333333
79984.488622522356481 269160.678085376751920
-3267.792578363696043 -210454.379232334372417
46257.363593155145794 -38546.483790939251583