Problem list
Log in
#coci00537 · COCI 2019/2020 Contest 2

Zvijezda

Diamond V 1.0 s 512 MB

Mirko and Slavko are spending their free time playing with polygons and watching a new season of The Biggest Loser. Mirko recently drew a convex polygon with an even number of vertices $N$. Slavko then considered each pair of oposite sides (two sides are opposite if there are ^{N} _{2} ^{−1} ^{sides} ^{between} ^{them),} ^{drew} straight lines that lie on those sides and colored them along with the part of the plane that lies between them and contains the polygon. Finally, Mirko found a set of $Q$ points and decided to challenge Slavko to answer for each point whether it lies in the colored or uncolored part of the plane. The new episode of The Biggest Loser is about to start and Slavko doesn’t have the time to answer Mirko’s queries. Can you help him?

Input

The first line contains an integer $T$ which is used as a parameter for generating Mirko’s queries. This number can be either 0 or 1. The second line contains an even integer $N$ from the task description. Each of the next $N$ lines contains two integers $X_{i}$, $Y_{i}$ (0 ≤|$Xi$|, |Y i| ≤$10^{9}$) which represent one of the polygon’s vertices. You can assume that the vertices are given in the counter clockwise order and that no three successive vertices are collinear. The next line contains an integer $Q$ from the task description. Each of the next $Q$ lines contains two integers $A_{i}$, $B_{i}$ (0 ≤|$Ai$|, |$Bi$| ≤$2 \cdot 10^{18}$) which are used as parameters for generating the point in the $i$-th of Mirko’s queries. Let $X_{i}$ be equal to the number of points in the first $i$ (inclusive) of Mirko’s queries that lie in the colored part of the plane. Naturally, $X_{0} = 0$. The point of Mirko’s $i$-th query should then be generated as: $P_{i}$ = ($A_{i}$ ⊕($T \cdot X^{3}$ _{$i - 1$}^{), Bi} ^{⊕(T} ^{·X3} _{$i - 1$}^{))} where ⊕represents the bitwise xor operation.

Output

The $i$-th line of output should contain the word "DA" (YES in Croatian) if the point from $i$-th of Mirko’s queries lies in the colored part of the plane. Otherwise, the $i$-th line should contain the word "NE" (NO in Croatian).

Constraints

Subtask 1 (20 points): $1 \le N$, $Q \le 2000$, $T = 0$

Subtask 2 (30 points): $1 \le N$, $Q \le 10^{5}$, $T = 0$

Subtask 3 (60 points): $1 \le N$, $Q \le 10^{5}$, $T = 1$

Example 1

Input
0
4
1 1
5 1
4 3
2 2
4
3 2
2 4
6 2
4 5
Output
DA
NE
DA
NE

Example 2

Input
0
6
-1 -1
2 -1
3 3
2 4
1 4
-2 1
6
2 2
3 0
1 -6
2 6
-5 5
5 10
Output
DA
DA
NE
NE
NE
NE

Example 3

Input
1
6
-1 -1
2 -1
3 3
2 4
1 4
-2 1
6
2 2
3 0
1 -6
2 6
-5 5
5 10
Output
DA
DA
DA
NE
NE
NE

Clarification of the second example: Clarification of the third example: The colored parts of the plane are the same as in the second example and the points in Mirko’s queries are: (2, 2), (2, 1), (9, −14), (25, 29), (−32, 30) and (30, 17).

Source
COCI 2019/2020 Contest 2
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code