#P12552. [UOI 2024] Points on a Line

    ID: 14117 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2024交互题Special JudgeUOI(乌克兰)

[UOI 2024] Points on a Line

题目描述

This is an interactive problem.

There are nn points on a number line with integer coordinates x1,x2,,xnx_1, x_2, \ldots, x_n. It is guaranteed that 1xin1\le x_i\le n for 1in1\le i\le n.

A point xkx_k is considered to be between points xix_i and xjx_j if and only if it belongs to the segment constructed on points xix_i and xjx_j. Formally, point xkx_k is between points xix_i and xjx_j if and only if xixkxjx_i \leq x_k \leq x_j or xjxkxix_j \leq x_k \leq x_i.

You need to find any two indices ii and jj such that all nn points are between points xix_i and xjx_j.

You can use the following query: select three indices (ii, jj, kk) and find out if point xkx_k is between points xix_i and xjx_j.

You are allowed to use no more than 2222222222 queries.

It is guaranteed that the coordinates of the points are fixed before the interaction begins. In other words, the interactor is not adaptive.

输入格式

The first line contains a single integer nn (3n21043 \le n \le 2 \cdot 10^4) --- the number of points.

输出格式

To make a query, output "?\tt{?} ii jj kk" (1i,j,kn1 \le i, j, k \le n), then output a newline character and perform the flush\tt{flush} operation.

In response to the query, the jury program will output a single integer ff (f{0,1}f \in \{0,1\}). If f=1f = 1, then point xkx_k is between points xix_i and xjx_j; if f=0f = 0, then point xkx_k is not between them.

If the query is invalid (i.e., the maximum number of queries is exceeded or the query parameters are invalid), the jury program will output -1\texttt{-1} and terminate. In this case, terminate the program to receive the verdict WrongAnswer\tt{Wrong Answer}.

When you are ready to provide an answer, output it in the format "!\tt{!} ii jj" (1i,jn1 \leq i, j \leq n), where ii and jj are the sought indices of points. After that, terminate the program.

The flush\tt{flush} operation is performed as follows:

  • fflush(stdout)\texttt{fflush(stdout)} or cout.flush()\texttt{cout.flush()} in C++\tt{C++};
  • System.out.flush()\texttt{System.out.flush()} in Java\tt{Java};
  • flush(output)\texttt{flush(output)} in Pascal\tt{Pascal};
  • sys.stdout.flush()\texttt{sys.stdout.flush()} in Python\tt{Python}.

You can see the templates given.

提示

4
? 1 4 2
1
? 1 4 3
1
! 1 4

In the example, the points have coordinates x=[1,2,3,4]x = [1, 2, 3, 4].

Scoring

  • (1717 points): n20n \le 20;
  • (1616 points): n100n \le 100;
  • (3030 points): n10000n \le 10000;
  • (2323 points): n20000n \le 20000, xi2x_i \le 2;
  • (1010 points): n12000n \le 12000;
  • (44 points): without additional constraints.