#P14195. [ICPC 2024 Hangzhou R] Identify Chord

    ID: 14068 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>2024交互题Special JudgeICPC杭州

[ICPC 2024 Hangzhou R] Identify Chord

题目描述

This is an interactive problem.\textit{This is an interactive problem.}

Grammy has an undirected cyclic graph of nn (4n1094 \le n \le 10^9) vertices numbered from 11 to nn. An undirected cyclic graph is a graph of nn vertices and nn undirected edges that form one cycle. Specifically, there is a bidirectional edge between vertex ii and vertex ((imodn)+1)((i\bmod n)+1) for each 1in1 \le i \le n.

Grammy thinks that this graph is too boring, so she secretly chooses a pair of non-adjacent\textit{non-adjacent} vertices and connects an undirected edge (called a chord) between them, so that the graph now contains nn vertices and (n+1)(n+1) edges.

Your task is to guess the position of the chord by making no more than 4040 queries. Each query consists of two vertices xx and yy, and Grammy will tell you the number of edges on the shortest path between the two vertices.

Note that the interactor is non-adaptive\textit{non-adaptive}, meaning that the position of the chord is pre-determined.

输入格式

There are multiple test cases. The first line of the input contains an integer TT (1T1031 \le T \le 10^3) indicating the number of test cases. For each test case:

The first line contains an integer nn (4n1094 \le n \le 10^9) indicating the number of vertices.

输出格式

To ask a query, output one line. First output \texttt{?} followed by a space, then output two vertices xx and yy (1x,yn1 \le x, y \le n) separated by a space. After flushing your output, your program should read a single integer indicating the number of edges on the shortest path between the two vertices.

To guess the position of the chord, output one line. First output !\texttt{!} followed by a space, then output two vertices uu and vv (1u,vn1 \le u, v \le n) separated by a space, indicating that the chord connects vertices uu and vv. After flushing your output, your program should read a single integer rr (r{1,1}r \in \{1, -1\}) indicating the correctness of your guess. If r=1r = 1 then your guess is correct, and your program should continue processing the next test case, or exit immediately if there are no more test cases. Otherwise if r=1r = -1 then your guess is incorrect, and your program should exit immediately to receive a Wrong Answer\texttt{Wrong Answer} verdict. Note that your guess does not count as a query.

To flush your output, you may use:

  • fflush(stdout)\texttt{fflush(stdout)} (if you use printf\texttt{printf}) or cout.flush()\texttt{cout.flush()} (if you use cout\texttt{cout}) in C and C++.
  • System.out.flush()\texttt{System.out.flush()} in Java.
  • stdout.flush()\texttt{stdout.flush()} in Python.
2
6

2

1

1
4

2

1


? 1 5

? 2 4

! 4 2


? 2 4

! 1 3

提示

The graphs in the sample test cases are illustrated as follows:

:::align{center} :::