#P11193. [COTS 2021] 虫 Kukac

    ID: 12354 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2021交互题Special JudgeO2优化COCI(克罗地亚)

[COTS 2021] 虫 Kukac

Background

Translated from Izborne Pripreme 2021 (Croatian IOI/CEOI Team Selection) D1T2. 3s,0.5G\texttt{3s,0.5G}

As everyone knows, insects can only sense clockwise and counterclockwise directions.

If you suspect the SPJ is incorrect, please contact the problem porter. SPJ code

Problem Description

This is an interactive problem.

On a 2D plane, there is a polygon PP with NN points. Note that PP is not necessarily convex (it can be concave). We number the points on the polygon in order from 11 to NN.

In addition, there is an extra point 00. Determine through interaction whether it is inside PP.

It is guaranteed that the polygon edges do not intersect. It is guaranteed that these (N+1)(N+1) points are pairwise distinct. It is guaranteed that no three points are collinear.

Definition: A,B,CA, B, C are in counterclockwise order if and only if, when looking from AA to BB, point CC is on the left side of the line ABAB, as shown in the left figure.

【Implementation Details】

Before the interaction starts, you need to read a line with two integers N,QN, Q, representing the number of vertices of the polygon and the maximum number of queries allowed.

Then, your program interacts with the interactive library through standard input/output. The following queries are allowed:

  • ? a b c\texttt{? a b c}: Ask whether points a,b,ca, b, c are in counterclockwise order. You must ensure that a,b,ca, b, c are pairwise distinct, and that 0a,b,cN0 \le a, b, c \le N.

    If a,b,ca, b, c are in counterclockwise order, the answer is 11; otherwise, the answer is 00.

After you determine the answer, output it in the following format:

  • ! x\texttt{! x}: If x=1x = 1, it means point 00 is inside the polygon; if x=0x = 0, it means point 00 is not inside the polygon.

After each output, do not forget to flush the buffer, for example: std::cout.flush()

Input Format

See 【Implementation Details】.

Output Format

See 【Implementation Details】.

5 125

1

1

0

0

? 1 2 3

? 0 4 1

? 2 5 4

? 0 1 5

! 0

Hint

Sample Explanation

Constraints

For 100%100\% of the testdata, it is guaranteed that 3N5003 \le N \le 500.

Reminder again: the polygon is not necessarily convex. It is guaranteed that the polygon edges do not intersect. It is guaranteed that these (N+1)(N+1) points are pairwise distinct. It is guaranteed that no three points are collinear.

Subtask ID NN \le Q=Q = Special Property Score
11 5050 N3N^3 Yes 55
22 No 2525
33 500500 N2N^2 1515
44 4N4N 2525
55 2N2N 3030

Special Property: PP is convex.

Translated by ChatGPT 5