Codeforces Round 945 (Div. 2)
D
Cat, Fox and Maximum Array Split
Codeforces
2400
原题
← CE →
翻译中…

This is an interactive problem.

翻译中…

Fox gave Cat two positive integers $n$ and $k$. She has a hidden array $a_1, \ldots , a_n$ of length $n$, such that $1 \leq a_i \leq n$ for every $i$. Now they are going to play the following game:

翻译中…

For any two integers $l, r$ such that $1 \leq l \leq r \leq n$, define $f(l, r) = (r - l + 1) \cdot \max\limits_{x=l}^r a_x$. In other words, $f(l, r)$ is equal to the maximum of the subarray $a_l, \ldots, a_r$ multiplied by its size.

翻译中…

Cat can ask Fox at most $2 n$ questions about the array. He will tell her two integers $l$ and $x$ ($1 \leq l \leq n, 1 \leq x \leq 10^9$), and she will tell him one integer $p$ as the answer — the smallest positive integer $r$ such that $f(l, r) = x$, or $n+1$ if no such $r$ exists.

翻译中…

Now, Cat needs to find the largest value $m$ such that there exists a sequence $c_1, \ldots, c_{k-1}$ such that $1 \leq c_1 \lt \ldots \lt c_{k-1} \lt n$ and $f(1, c_1) = f(c_1 + 1, c_2) = \ldots = f(c_{k-1}+1, n) = m$. If no such $m$ exists, he should indicate this and take $-1$ as the answer. Note that for $k = 1$, $m$ is always equal to $f(1, n)$.

翻译中…

In other words, the goal is to find the largest $m$ such that you can split the array into exactly $k$ subarrays ($k$ is the constant given to you in the beginning of the interaction) so that all the subarrays have the product of their length and their maximum equal to $m$, or determine that no such $m$ exists. Every element should belong in exactly one of the subarrays.

翻译中…

Cat doesn't know what he should do, so he asked you to play the game for him.

翻译中…

Interaction

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains two positive integers $n$ and $k$ ($1 \leq k \leq n \leq 10^4$) — the length of the hidden array and the number of subarrays in the desired split.

翻译中…

Now you are allowed to make queries in the following way — print one line of the form "$\mathtt{?} \ l \ x$" (it must hold that $1 \leq l \leq n$, $1 \leq x \leq 10^9$) and you will receive the smallest integer $r$ such that $l \leq r \leq n$ and $f(l, r) = x$, or $n + 1$ if no such $r$ exists.

翻译中…

If you want to print the answer, output "$\mathtt{!} \ m$" and you will recieve $1$ if your answer is correct and $-1$ otherwise. In the first case, the interaction continues with the next test case. Note that printing the answer doesn't count towards the number of queries made. Please note that you don't receive the values for the next test case immediately, you will first have to read whether your answer to the last test case was correct.

翻译中…

If you receive the integer $-1$ at any moment, it means your program has made an invalid query, exceeded the query limit, or gave an incorrect answer. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

After printing a query, do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

翻译中…
  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.
翻译中…

It is guaranteed that the total sum of $n$ over the test cases won't exceed $10^4$.

翻译中…

Hacks

翻译中…

The format of the hacks should be the following: the first line should contain one integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases. The description of the test cases should follow.

翻译中…

The first line of each test case should contain two integers $n$ and $k$ ($1 \leq k \leq n \leq 10^4$) — the length of the array $a$ and the number of subarrays you want to split it into.

翻译中…

The second line should contain $n$ integers $a_1, a_2, \ldots, a_n $ ($1 \leq a_i \leq n $).

翻译中…

The sum of $n$ over all test cases should not exceed $10^4$.

翻译中…

Note

翻译中…

The hidden arrays in the three testcases are $[1]$, $[1, 2]$ and $[1, 3, 6, 1, 2, 1]$. In the second testcase, no split satisfies the constraints, so the answer is $-1$.

翻译中…

The answer for the first query of the third testcase is $7$ since no valid $r$ exists. For the second query of the third testcase, since $2 \cdot \max(1, 3) = 6$, we will get $2$ as the answer, since $r = 1$ doesn't satisfy the constraint.

翻译中…

The sample interaction guessed all three answers ($1, -1$ and $6$) correctly, so it received $1$ after each answer.

翻译中…

样例

Input #1
3
1 1

1
2 2

1

3

1
6 3

7

2

3

6

1
Output #1
! 1

? 1 1

? 2 1

! -1

? 1 9

? 1 6

? 3 6

? 4 6

! 6
InputCopy OutputCopy
题目信息
题号
1973D
时间限制
3 s
内存限制
256 MB
标签
暴力
交互题
数学

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