#P7998. [WFOI - 01] 猜数(guess)

    ID: 9084 远端评测题 300ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP洛谷原创交互题Special Judge其它技巧洛谷月赛

[WFOI - 01] 猜数(guess)

Background

This is an interactive problem. The interaction library is adaptive. Please note the special time limit.

Remember to flush the output buffer after every output.

Simplified statement: Link\texttt{Link}.

Problem Description

You need to guess a positive integer qq, and it is guaranteed that q[1,n]q\in [1,n].

Each time, you may make a query like ? x y, and the interaction library will deliberately choose a number zz from [x,y][x,y].

Then the interaction library will output an answer in the form u v, meaning that the chosen number is uu, and its relation to qq is vv.

Specifically:

  • When the library returns v=0v=0, it means u<qu<q.
  • When the library returns v=1v=1, it means u=qu=q.
  • When the library returns v=2v=2, it means u>qu>q.

The cost of one query is 1yx+1\dfrac{1}{y-x+1}.

You can output what you believe is the correct answer using ! x.

Now you need to determine qq.


Let your total cost be xx. The score you get on each test point depends on your total cost as follows (each test point has a full score of 1010 points):

  • If x1.9813035x\le 1.9813035, you can get 10 pts\text{10 pts}.
  • If 1.9813035<x121.9813035 < x \le 12, you can get $\lfloor(12-x)\times0.7 \div 1.00186965\rfloor \text{ pts}$.
  • If x12x\ge12, you can get 0 pts\text{0 pts}.

Note that after every operation, you must call the following function to flush the buffer:

  • For C/C++: fflush(stdout).
  • For C++: std::cout << std::flush.
  • For Java: System.out.flush().
  • For Python: stdout.flush().
  • For Pascal: flush(output).
  • For other languages, please check the corresponding language documentation by yourself.

Interaction Format

At the beginning, the interaction library will give you nn.

Then you may query or answer as described above.

After you output the answer, please terminate your program immediately.

Input Format

See Interaction Format.

Output Format

See Interaction Format.

2

1 0
 

? 1 2

! 2
3

1 0

3 2
 

? 1 3

? 3 3

! 2

Hint

  • Sample 11 Explanation:

    After querying, we find that 1<x21<x\le2, so x=2x=2.

  • Sample 22 Explanation:

    After the first query, we find that 1<x31<x\le3.

    After the second query, we find that 1<x<31<x<3, so x=2x=2.

【Constraints】

Test Point ID nn \le Test Point ID nn\le
1\texttt{1} 11 6\texttt{6} 2×1032\times 10^3
2\texttt{2} 77 7\texttt{7} 10410^4
3\texttt{3} 2020 8\texttt{8} 5×1045\times 10^4
4\texttt{4} 8080 9\texttt{9} 10510^5
5\texttt{5} 300300 10\texttt{10}

For 100%100\% of the testdata, 1n1051\le n\le10^5, 1q,un1\le q,\forall u\le n, v{0,1,2}\forall v\in\{0,1,2\}.

It is guaranteed that each query to the interaction library runs in O(1)\mathcal O(1) time.

Translated by ChatGPT 5