Good Bye 2025
E
Flatten or Concatenate
Codeforces
2000
原题
← DF →
翻译中…

This is an interactive problem.

翻译中…

While procrastinating at work, Dilhan the elf stumbled upon two arrays $a$ and $b$. Initially, both of them consist of a single integer $2^k$ (i.e., $a=b=[2^k]$), where $k$ is a non-negative integer.

翻译中…

Dilhan then applied the following two types of operations an arbitrary number of times (possibly zero), in any order:

翻译中…
  1. Flatten — Choose either $a$ or $b$, and select any element $x$ that is maximal within that array ($x$ does not need to be maximal in the other array). Then, replace $x$ with two copies of $\frac x2$ in the same position. This operation can only be applied if $x$ is even.
  2. Concatenate — Set both $a$ and $b$ to be $a+b$, where $+$ denotes array concatenation.
翻译中…

After performing these operations, Dilhan discards $b$, hides $a$ from you, and challenges you to a game.

翻译中…

Let $n$ be the length of the hidden array $a$. You may make the following query:

翻译中…
  • Choose an interval $[l, r]$ ($1\le l\le r\le n$), and Dilhan will tell you the sum $a_l+a_{l+1}+\cdots+a_r$.
翻译中…

Determine the value of the maximum element of $a$ by making at most $300$ queries.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of $a$.

翻译中…

It is guaranteed that $1\le a_i\le 2^{30}$, and the array $a$ can be generated by the process described in the statements.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Interaction

翻译中…

For each test case, you are first given an integer $n$ — the length of the hidden array $a$. You may then make up to $300$ queries.

翻译中…

To make a query, print a line in the following format:

翻译中…
  • $\texttt{?}\;l\;r$ ($1\le l\le r\le n$) — the indices chosen for the query.
翻译中…

After you print a query, the interactor will respond with a single integer — the sum $a_l+a_{l+1}+\ldots+a_r$.

翻译中…

To report that you have determined the value of the maximum element of $a$, print your answer in the following format:

翻译中…
  • $\texttt{!}\; m$ ($1\le m\le 2^{30}$) — the value of the maximum element.
翻译中…

Printing the answer does not count as one of the $300$ queries.

翻译中…

After printing the answer, proceed to the next test case. If the current test case is the last one, terminate the program.

翻译中…

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

The interactor in this problem is not adaptive. In other words, the array $a$ is fixed before any queries and will not change during the interaction.

翻译中…

Hacks are disabled in this problem.

翻译中…

$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.

翻译中…

Note

翻译中…

In the first test case, Dilhan's hidden array $a$ is $[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$. It can be generated by the following process:

翻译中…

#Type$a$ after operation$b$ after operation0$[4]$$[4]$1Flatten $a$$[\underline 4] \to {[2, 2]}$$[4]$2Flatten $b$$[2, 2]$$[\underline 4] \to {[2, 2]}$3Flatten $a$$[2, \underline 2] \to {[2, 1, 1]}$$[2, 2]$4Concatenate$[2, 1, 1, 2, 2]$$[2, 1, 1, 2, 2]$5Flatten $a$$[\underline 2, 1, 1, 2, 2]\to {[1, 1, 1, 1, 2, 2]}$$[2, 1, 1, 2, 2]$6Concatenate$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$

翻译中…
  • For the query $\mathtt{?\;3\;8}$, the jury responded with $1+1+2+2+2+1=9$;
  • For the query $\mathtt{?\;1\;4}$, the jury responded with $1+1+1+1=4$;
  • For the query $\mathtt{?\;5\;11}$, the jury responded with $2+2+2+1+1+2+2=12$.
翻译中…

And the value of the maximum element of $a$ is $2$.

翻译中…

In the second test case, the array $a$ has only one element. By the query, the value of the only element is $1$, and it must also be the maximum value.

翻译中…

In the third test case, Dilhan's hidden array $a$ is $[4, 4, 4, 4, 4, 4, 4, 4]$. It can be generated by the following process:

翻译中…

#Type$a$ after operation$b$ after operation0$[4]$$[4]$1Concatenate$[4, 4]$$[4, 4]$2Concatenate$[4, 4, 4, 4]$$[4, 4, 4, 4]$3Concatenate$[4, 4, 4, 4, 4, 4, 4, 4]$$[4, 4, 4, 4, 4, 4, 4, 4]$

翻译中…

And the value of the maximum element of $a$ is $4$.

翻译中…

In the fourth test case, Dilhan's hidden array $a$ is $[2^{29}, 2^{29}, 2^{30}, 2^{29}, 2^{28}, 2^{28}, 2^{29}, 2^{29}]$.

翻译中…

样例

Input #1
4
11

9

4

12

1

1

8

4

4

4

4

8
Output #1
? 3 8

? 1 4

? 5 11

! 2

? 1 1

! 1

? 1 1

? 2 2

? 3 3

? 4 4

! 4

! 1073741824
InputCopy OutputCopy
题目信息
题号
2178E
所属比赛
时间限制
3 s
内存限制
512 MB
标签
二分
分治
交互题

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。