luogu#P7849. 「JZOI-2」猜数列
「JZOI-2」猜数列
Background
The team members are all thinking about organizing the anniversary celebration, but Xiaoxi just wants to slack off.
So Xiaoxi took out their favorite sequence to test you.
Problem Description
Xiaoxi has a shuffled arithmetic progression .
You can make two types of queries:
- Ask for the order relationship (in the arithmetic progression, in the non-mod sense) between the numbers at indices in the original sequence.
- Ask for the value (in the arithmetic progression, in the mod sense) of the number at index in the original sequence.
However, due to a problem with the interactive library, query type 2 can be used at most times.
Given the length of the arithmetic progression, the query limit , and the fixed modulus , find the common difference of this arithmetic progression.
The total number of queries must not exceed . After finishing the interaction, output the answer immediately.
Interaction:
Input the sequence length and the query limit to start the interaction.
During the interaction, you may perform the two types of queries described above.
For the first type of query, the interactive library returns meaning or meaning . The query format is > x y.
For the second type of query, the interactive library returns a positive integer . The query format is ? x.
After you determine the answer, output one line in the form ! d and stop the interaction.
After outputting a line, flush the buffer:
In C++, use fflush(stdout) or cout.flush().
In Pascal, use flush(output).
In Python, use stdout.flush().
For other languages, please check the documentation yourself.
Please follow the statement to complete the interaction. Making invalid queries may cause issues such as TLE or WA.
Input Format
See Interaction.
Output Format
See Interaction.
The testdata guarantees that there will not be multiple possible values of .
3 6
1
2
3
? 1
? 2
? 3
! 1
Hint
For of the testdata, it is guaranteed that .
For the other of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that , , .
Translated by ChatGPT 5