#P3839. [IOI 2017] The Big Prize
[IOI 2017] The Big Prize
Description
“The Big Prize” is a well-known TV game show. This time you are lucky to reach the final round. There are boxes in a row from left to right, numbered from to , and you are standing in front of them. Each box contains exactly one prize, and you must open a box to see which prize it holds. There are distinct types of prizes. These types are ordered from to in decreasing order of value.
The type prize is a diamond, the most valuable. Across all boxes there is exactly one diamond. The type prize is a lollipop, the least valuable. To make the game more exciting, cheaper prizes are far more numerous than expensive prizes. More specifically, for every with , if there are prizes of type , then there are strictly more than prizes of type .
Your goal is to win the diamond. At the end of the game, you must open one box and take the prize inside. Before choosing which box to open, you may ask the host, Rambod, some questions. In each question, you choose a box index . Rambod answers with an array of two integers. They mean:
- Among the boxes to the left of box , there are exactly boxes whose prizes are more valuable than the prize in box .
- Among the boxes to the right of box , there are exactly boxes whose prizes are more valuable than the prize in box .
For example, suppose , and in your query you choose . Rambod’s answer is . This means:
- Among boxes and , exactly one box has a prize more valuable than the prize in box .
- Among boxes , exactly boxes have prizes more valuable than the prize in box .
Your task is to find the box containing the diamond by asking as few questions as possible.
Input Format
When your program starts, it should read a positive integer .
You may issue queries in the following format:
? i
Meaning you choose to ask about box . You must ensure .
Then you should read two integersa[0] a[1], which is the interactor’s response.
You may report your answer in the following format:
! i
Meaning you are certain that the diamond is in box .
Then you must terminate your program immediately.
Output Format
After issuing a query, do not forget to flush the output buffer. You may use:
fflush(stdout)orcout.flush()in C++.stdout.flush()in Python.- For other languages, refer to their documentation.
8
0 3
0 1
1 2
0 0
2 1
2 1
1 0
3 0
? 0
? 1
? 2
? 3
? 4
? 5
? 6
? 7
! 3
Hint
Sample explanation
8
3 2 3 1 3 3 2 3

The figure illustrates this example. The upper part shows the prize type in each box. The lower part illustrates the query ? 2.
Constraints
- .
- The prize type in each box is between and (inclusive).
- There is exactly one type prize.
- For all , if there are prizes of type , then there are strictly more than prizes of type .
Subtasks and Scoring
- (20 points) There is exactly diamond and lollipops (so ). You may ask at most queries.
- (80 points) No additional constraints.
In subtask 2 you can receive partial credit. Let be the maximum number of queries you use over all testdata in this subtask; then your score for this subtask is computed as follows:
| Queries | Score |
|---|---|
(reported as Wrong Answer in CMS) |
|
Translated by ChatGPT 5
京公网安备 11011102002149号