#P8111. [Cnoi2021] 区间

[Cnoi2021] 区间

Background

Cirno has an interval [a,b](1abn)[a,b](1\le a \le b \le n), and your task is to help Rumia guess this interval within the required number of queries.

Each time, you may ask Cirno about a number kk, and Cirno will tell you the relationship between this number and the interval [a,b][a,b].

Problem Description

To guess this interval, you need to implement a function std::pair<int,int> Guess(int n,int c). This function must correctly determine a closed sub-interval [a,b][a,b] of [1,n][1,n] using at most cc queries, and return the interval you finally determine in the form of std::pair<int,int>.

You may call a function in the interactive library called Query, with the prototype int Query(int x). Its return value is:

  • If x<ax < a, return 1-1.
  • If x[a,b]x \in [a,b], return 00.
  • If x>bx > b, return 11.

You must call Query no more than cc times to get the score for that test point; otherwise, the score for that test point is 00. For how to call this function, please refer to the “Notes / Hint” section.

Within one test point, your Guess function may be called multiple times, up to at most 50005000 times. To ensure your program does not time out, you also need to implement a function void init(). This function will be called only once by the interactive library at the beginning. Of course, its implementation may be empty.

Since Rumia’s compiler only supports C++, you may only use C++ (including C++, C++11, C++14, C++17) to solve this problem.

Input Format

In the sample, four numbers nn, aa, bb, cc are given as input. You cannot read these numbers.

Output Format

In the sample, three numbers ll, rr, qq are given as output, representing the interval you guessed and the number of Query calls. You do not need to output these.

5 2 3 5
2 3 0

Hint

Sample Explanation

The interval to be found is [2,3][2,3]. The possible range of the left and right endpoints is [1,5][1,5], and you can guess at most 55 times.

Constraints and Conventions

For all testdata, it is guaranteed that 1abn1 \le a \le b \le n; except for SubtaskExtra, it is guaranteed that 1n15001\le n\le1500.

Subtasks

Subtask1 (1010 points): c=nc=n.

Subtask2 (3030 points): c=30c=30.

Subtask3 (3030 points): c=22c=22.

Subtask4 (3030 points): c=20c=20.

Extra Task

SubtaskExtra (11 point): 1n1061\le n\le 10^6, $c=\lfloor\log_2 n\rfloor+\lfloor\log_2 \frac{4n}{3}\rfloor$.

This problem uses Special Judge. Both 100100 and 101101 points are considered Accepted.

Notes

If you do not know how to solve interactive problems, you may refer to this problem.

The template program and the template interactive library for this problem can be found in the attachments SampleProgram.cpp and SampleInteractor.cpp.

Input Format

Output Format

Translated by ChatGPT 5