#P11083. [ROI 2019] 黑洞 (Day 1)

    ID: 10689 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2019交互题Special JudgeROI(俄罗斯)

[ROI 2019] 黑洞 (Day 1)

Background

Translated from ROI 2019 D1T4.

This is an interactive IO problem.

Scientists plan to measure the radiation level of a series of black holes. A black hole’s radiation level is represented by an integer from 11 to nn. To measure each black hole’s radiation level, a special orbital probe equipped with a radiation sensor is used. The sensor mounted on the probe can answer the following query: given a value xx, determine whether the radiation level is greater than or equal to xx. Unfortunately, due to a software bug, the sensor’s reply may be incorrect. However, after the first incorrect reply, the probe’s state changes, and for all subsequent queries it gives only correct replies.

The scientists want to determine the radiation level of several black holes by asking the probe as few queries as possible.

Problem Description

Write a program that interacts with the simulation library of the probe sensor and determines the radiation level of each black hole.

For each run of the solution program, you must solve the problem for multiple black holes with the same nn (that is, you need to determine the radiation levels of multiple black holes, and each radiation level is between 11 and nn). The number of black holes in each run is at most 100100.

For each test, the interactive library stores a value qq, the maximum number of queries allowed for one black hole. It is guaranteed that no matter how the interactive library chooses to answer, qq queries are enough to solve the problem. This number will not be given to your program. If your program performs more than qq queries for a black hole, the test will receive WA.

Note: In the WA case described above, the test may appear as TLE, possibly because the interactive library has already terminated and returned, but the program is still waiting for a reply to that query. When TLE happens, you can check the detailed information returned for that test to confirm whether it is a real timeout or caused by exceeding the query limit.

Input Format

First, read an integer nn, the maximum possible radiation level of a black hole. This number is the same for all black holes in this run. After reading nn, your program should interact with the library and gradually determine the radiation level of one or more black holes.

After outputting your answer for one black hole’s radiation level, the program should read one more line. If you need to continue studying the next black hole, the string read from the library will be Correct; if all black holes have been finished, the string will be Done.

Output Format

To make a query, the program must output a string in the format ? x, where xx is a positive integer. As a reply, the interactive library will give your program a string, either Yes (if the sensor’s reply is not wrong, it means the black hole’s radiation level is greater than or equal to xx), or No (if the sensor’s reply is not wrong, it means the black hole’s radiation level is less than xx).

If your program determines the answer, it should output a line ! x, where xx is the radiation level of the black hole you found. This answer is considered correct if xx is the only radiation level value that contradicts no more than one reply from the interactive library. If an incorrect answer is given, the program will be terminated immediately, and the result of that test will become WA.

2

Yes

No

Yes

Correct

No

No

Done

? 2

? 2

? 2

! 2

? 2

? 2

! 1
3

Yes

Yes

No

Yes

No

Done

? 2

? 2

? 3

? 3

? 3

! 2

Hint

Sample explanation:

In the first example, for the first black hole, after the first two queries it is unknown which one of the sensor’s answers is wrong, so a third query is needed.

In the second example, one possible interaction for n=3n = 3 is shown, where the program can find the answer within 55 queries. It can be proven that the answer cannot be determined within 44 queries.

In both examples, the interactive library sets q=30q=30, and clearly neither example exceeds the limit.

Please note that the interactive library may give different answers even if your program outputs exactly the same queries as in the samples.

Constraints:

Subtask Score nn\le Special property of qq
11 77 10001000 q=30q=30
22 88 q=21q=21
33 66 44
44 99 77
55 1212
66 2525
77 44 4040
88 55 8080
99 150150
1010 88 300300
1111 77 500500
1212 55 10001000
1313 20002000
1414 40004000
1515 80008000
1616 1500015000
1717 3000030000

For 100%100\% of the data, n30000n\le30000. In each test, the value of qq is guaranteed to be sufficient to solve the problem, no matter how the interactive library answers.

It is guaranteed that after each answer given by the interactive library, there always exists a radiation level value that satisfies all previous query answers (except the one wrong answer). The interactive library may adjust its behavior, including choosing which known answer is wrong, and determining the radiation level of the black hole being studied based on the queries asked by the solution program.

Translated by ChatGPT 5