P17698 Reversal
Background
Problem source: [HT-129-Div.1] Walnut NOI Qualifier Mock Contest.
When submitting to Luogu, you do not need to include the header `#include "reversal.h"`. Simply copy
```
std::pair solve(int n);
int query(const std::string &S);
```
to the beginning of your program, and compile with C++17 or a later version.
Description
**This is a function-style interactive problem.**
The interaction library holds a hidden interval $[l,r]$, where $1\le l
Input Format
### Testing Program Format
The format of `sample.in` is:
```text
n l r mask
```
Here, $[l,r]$ is the hidden interval used by the local grader.
If the valid nonzero replies for the $(k+1)$-th `query` are $\min T$ and $\max T$, then the $k$-th binary bit of `mask`, counted from the lowest bit, decides which one is returned: when the bit is $0$, $\min T$ is returned; when it is $1$, $\max T$ is returned.
If that query returns $0$, the corresponding binary bit does not affect the result.
To cover all left/right reply combinations for the first $5$ queries, you can fix $n,l,r$ and let `mask` take the values $0,1,\ldots,31$ in turn.
The local `grader.cpp` is only for debugging; the official judging uses a stronger adaptive interaction library, but the interface in `reversal.h` is exactly the same.
Output Format
N/A
Explanation/Hint
### Constraints
This problem has $3$ testpoints. All sets of testdata within a testpoint must be solved correctly; otherwise, you get $0$ points for that testpoint.
| Testpoint No. | Score | $n\le$ |
|:-:|:-:|:-:|
| $1$ | $10$ | $10$ |
| $2$ | $20$ | $10^3$ |
| $3$ | $70$ | $2\times 10^5$ |
For $100\%$ of the testdata, it is guaranteed that $2\le n\le 2\times 10^5$.
### Scoring
For a testpoint where all answers are correct, let $Q_i$ be the number of queries used on the $i$-th set of testdata, and let
$$
Q=\max_i Q_i.
$$
Define
$$
f(Q)=
\begin{cases}
1, & Q\le 5,\\
0.8^{Q-5}, & 6\le Q\le 15.
\end{cases}
$$
If the testpoint is worth $\mathrm{score}$ points, then you get $\lfloor f(Q)\cdot \mathrm{score} \rfloor$ points for that testpoint.
If on any set of testdata the answer is wrong, the format of a `query` call is invalid, the number of queries exceeds the limit, or the program encounters any other error, you get $0$ points for the entire testpoint.
Translated by QwenWork