#P8568. [JRKSJ R6] func

    ID: 7672 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学二分2022洛谷原创交互题Special JudgeO2优化

[JRKSJ R6] func

Description

This is an interactive I/O problem.

You have a linear function f(x)=kx+bf(x)=kx+b (1xn11\le x \le n-1). This linear function satisfies that kk and bb are both integers and k>0k>0.

vectorwyx modified this function. Specifically, he chooses an integer tt (1tn11\le t \le n-1), shifts the part of the function on the line x=tx=t and to its right by 11 unit to the right, and then connects the endpoints of the two parts with a line segment, obtaining a piecewise function g(x)g(x):

$$g(x)=\begin{cases} kx+b&1\le x<t\\ kt+b& t\le x <t+1\\ k(x-1)+b& t+1\le x \le n \end{cases}$$

Please obtain the value of tt through interaction.

Interaction

There are multiple test cases in one test point.

  1. First read an integer TT from standard input, representing the number of test cases.
  2. Next, you will interact for TT test cases. For each test case, first read three integers n,Q,Pn,Q,P from standard input.
  3. You can make a query by outputting ? l r p (1lrn1\le l \le r \le n, 2pP2\le p \le P) to standard output. In one test case, you can perform at most QQ ? operations. The interactor will process your query in the following order and send the result to standard input:
    • If your query range is invalid, the answer is 2-2. The interactor will immediately return WA. You must exit your program immediately to avoid TLE caused by interacting with an already terminated interactor.
    • If g(l)=g(r)g(l)=g(r), the answer is 1-1.
    • Otherwise, the answer is (g(l)+g(r))modp(g(l) + g(r))\bmod p.
  4. You can output ! t to standard output to give the answer. You can answer only once, and the answer operation must be the last operation you perform in each test case. After the interaction ends, read an integer xx (0 or 1) from standard input. If x=1x=1, your answer for the current test case is correct, and you should go back to step 22 to proceed to the next test case. Otherwise, if x=0x=0, you must exit your program immediately.

Do not forget to flush the output buffer after each output, otherwise you will get TLE.

Below are some ways to flush the output buffer in different languages:

  • C++: fflush(stdout) or cout.flush().
  • C: fflush(stdout).
  • Java: System.out.flush().
  • Python: stdout.flush().
  • Pascal: flush(output).
  • Other languages: please refer to the documentation of the corresponding language.

Input Format

See “Interaction”.

Output Format

See “Interaction”.

1
5 999 999

0

1

1


? 1 3 2

? 4 5 2

! 3

Hint

Sample Explanation

Note that the sample is only used to show the interaction rules, and it may not be logically meaningful.

Sample #1

f(x)=3x2f(x)=3x-2 (1x41\le x \le 4), t=3t=3.

$$g(x)=\begin{cases} 3x-2&1\le x<3\\ 7& 3\le x <4\\ 3x-5& 4\le x \le 5. \end{cases}$$

So the result of the first query is (g(1)+g(3))mod2=(1+7)mod2=0(g(1) + g(3))\bmod 2 = (1+7)\bmod 2=0, and the result of the second query is (g(4)+g(5))mod2=(7+10)mod2=1(g(4)+g(5))\bmod 2 = (7+ 10)\bmod 2=1.

Constraints

This problem uses bundled judging. Also, there is no restriction that one subtask contains all other subtasks.

Subtask Score nn Q=Q= P=P= g(x)g(x)\le Special Property
11 1010 109\le 10^9 4242 2×10182\times 10^{18} 101810^{18} None
22 2020 3030 22 Slope kk is odd
33 3030 4242 5050 None
44 3939 3232
55 11 =1162261531 = 1162261531 78571258470614727357857125847061472735

For 100%100\% of the data, it is guaranteed that 1T101 \le T \le 10, 2n11622615312\le n\le 1162261531. Also, $\forall x \in [1,n], 0 \le g(x)\le 7857125847061472735$.

Notes

Since there is no restriction that one subtask contains all other subtasks, the upper bounds of nn and g(x)g(x) in the “For 100%100\% of the data” part have no real meaning. However, if we directly wrote “For 100%100\% of the data, n2n \ge 2, g(x)0g(x)\ge 0”, some reviewers might reject it as “Is this what you call constraints?”. Therefore, this meaningless upper bound is kept in this problem statement.

Translated by ChatGPT 5