#P3316. [SDOI2014] 里面还是外面

[SDOI2014] 里面还是外面

Description

Alice gives a simple NN-gon on the plane. A simple NN-gon consists of NN given endpoints and straight segments connecting adjacent points. In particular, we consider vertex 11 adjacent to vertex NN.

For distinct boundary segments, they only intersect at common endpoints. Sometimes Alice points to a point in the plane and asks Bob: “Is this point inside the polygon, outside the polygon, or on the boundary?”

At that time, if the pointed point is a vertex of the polygon or lies on any edge of the polygon, it is considered to be on the boundary. Sometimes, to increase the difficulty, Alice deletes the edge connecting aa and bb, inserts a new point cc (the newly inserted point is guaranteed not to coincide with any existing endpoint and not to lie on any existing edge), and then adds edges from aa to cc and from bb to cc, thereby obtaining a new simple polygon.

Alice guarantees that the figure obtained by such an operation is always a simple polygon. What Bob has to do is answer Alice’s questions correctly. In fact, each of Alice’s questions will be determined by Bob’s previous answer: although this answer is unique, it implies that if Bob cannot answer the previous question, he cannot get Alice’s next question.

However, Alice’s modifications are indeed prepared in advance. In detail: each modification command by Alice can be viewed as a 6-tuple xa,ya,xb,yb,xc,yc\langle x_a, y_a, x_b, y_b, x_c, y_c \rangle, which means the edge between (xa,ya)(x_a, y_a) and (xb,yb)(x_b, y_b) is deleted, and a new point (xc,yc)(x_c, y_c) is inserted.

We guarantee that the points at coordinates (xa,ya)(x_a, y_a) and (xb,yb)(x_b, y_b) always exist. Because Alice guarantees that all appearing points (this includes query points) have non-negative integer coordinates, all less than 10910^9, and among the polygon’s points (this does not include query points) any two points have distinct xx-coordinates and also distinct yy-coordinates. Therefore, for each query Alice will give 7 non-negative integers: rr, xinx_{\text{in}}, yiny_{\text{in}}, xoutx_{\text{out}}, youty_{\text{out}}, xbdx_{\text{bd}}, ybdy_{\text{bd}}. The actual query point (X,Y)(X, Y) for this query is determined by the previous query point (x0,y0)(x_0, y_0) and the previous answer. For example, if the previous query point was outside the polygon, then:

X=(r×x0+xout)mod109X = (r \times x_0 + x_{\text{out}}) \bmod 10^9 Y=(r×y0+yout)mod109Y = (r \times y_0 + y_{\text{out}}) \bmod 10^9

For the first query, assume x0=y0=0x_0 = y_0 = 0, i.e., treat (0,0)(0, 0) as the previous query.

Similarly, if the previous point was inside, replace xout,youtx_{\text{out}}, y_{\text{out}} with xin,yinx_{\text{in}}, y_{\text{in}}; if it was on the boundary, use xbd,ybdx_{\text{bd}}, y_{\text{bd}}.

Input Format

The first line contains an integer NN, the number of vertices of the initial polygon.

Then follow NN lines, each with a pair of non-negative integers xx and yy (0x,y<1090 \leq x, y < 10^9). They describe all vertices of the polygon in some order and are indexed from 11 to NN. Here we only assume that the point (10100,10100)(10^{100}, 10^{100}) in the plane is certainly outside the polygon. The next line contains an integer QQ, the total number of operations.

Each of the next QQ lines starts with a number pp. If p=0p = 0, it is a query; if p=1p = 1, it is a modification.

  • For a query, the next 7 non-negative integers are: rr, xinx_{\text{in}}, yiny_{\text{in}}, xoutx_{\text{out}}, youty_{\text{out}}, xbdx_{\text{bd}}, ybdy_{\text{bd}}.
  • For a modification, the next 6 integers are: xax_a, yay_a, xbx_b, yby_b, xcx_c, ycy_c.

Output Format

For each query operation, output a single line containing exactly one string: either in, out, or bd (all lowercase), indicating that the query point is inside the polygon, outside the polygon, or on the boundary, respectively.

6
249999999 499999998
583333331 83333333
83333333 333333332
333333332 999999996
833333330 749999997
499999998 833333330
12
0 1 872826049 679758020 472526437 270998755 15447952 502239247
1 833333330 749999997 499999998 833333330 916666663 666666664
1 833333330 749999997 916666663 666666664 416666665 916666663
0 1 371653715 747730364 409617871 21996163 118531999 759280767
1 249999999 499999998 583333331 83333333 666666664 166666666
0 1 195920917 488293591 322952040 262793733 678458193 506876149
0 1 203963007 782710007 391614158 831643205 340800821 896322422
0 1 498571077 461554269 765704840 973009111 152064733 114249255
1 499999998 833333330 249999999 499999998 999999996 583333331
0 1 159294077 702544938 787871788 619972292 941209243 950700951
0 1 791254252 411705638 382076333 263993056 306662346 47793905
0 1 13359599 513224793 415037020 28305143 48117026 34994422
out
out
in
in
out
out
out
in

Hint

For 100% of the testdata: N50000N \leq 50000, Q50000Q \leq 50000, all coordinates are non-negative and less than 10910^9, and rr is either 11 or 00.

Translated by ChatGPT 5