#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 nn boxes in a row from left to right, numbered from 00 to n1n-1, 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 v5v\leq5 distinct types of prizes. These vv types are ordered from 11 to vv in decreasing order of value.

The type 11 prize is a diamond, the most valuable. Across all boxes there is exactly one diamond. The type vv 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 tt with 2tv2\leq t \leq v, if there are kk prizes of type t1t-1, then there are strictly more than k2k^2 prizes of type tt.

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 ii. Rambod answers with an array aa of two integers. They mean:

  • Among the boxes to the left of box ii, there are exactly a[0]a[0] boxes whose prizes are more valuable than the prize in box ii.
  • Among the boxes to the right of box ii, there are exactly a[1]a[1] boxes whose prizes are more valuable than the prize in box ii.

For example, suppose n=8n=8, and in your query you choose i=2i=2. Rambod’s answer is a=[1,2]a=[1,2]. This means:

  • Among boxes 00 and 11, exactly one box has a prize more valuable than the prize in box 22.
  • Among boxes 3,4,,73,4,\cdots,7, exactly 22 boxes have prizes more valuable than the prize in box 22.

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 nn.

You may issue queries in the following format:

  • ? i
    Meaning you choose to ask about box ii. You must ensure 0i<n0\leq i<n.
    Then you should read two integers a[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 ii.
    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) or cout.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

  • 3n2000003\leq n \leq200000.
  • The prize type in each box is between 11 and vv (inclusive).
  • There is exactly one type 11 prize.
  • For all 2tv2\leq t \leq v, if there are kk prizes of type t1t-1, then there are strictly more than k2k^2 prizes of type tt.

Subtasks and Scoring

  1. (20 points) There is exactly 11 diamond and n1n-1 lollipops (so v=2v=2). You may ask at most 1000010000 queries.
  2. (80 points) No additional constraints.

In subtask 2 you can receive partial credit. Let qq 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
q>10000q>10000 00 (reported as Wrong Answer in CMS)
6000<q100006000<q\le10000 7070
5000<q60005000<q\le6000 80q500010080-\dfrac{q-5000}{100}
q5000q\le5000 8080

Translated by ChatGPT 5