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 AA.

You can make two types of queries:

  1. Ask for the order relationship (in the arithmetic progression, in the non-mod sense) between the numbers at indices x,yx, y in the original sequence.
  2. Ask for the value (in the arithmetic progression, in the mod sense) of the number at index xx in the original sequence.

However, due to a problem with the interactive library, query type 2 can be used at most qq times.

Given the length nn of the arithmetic progression, the query limit qq, and the fixed modulus p=109+7p=10^{9}+7, find the common difference dd of this arithmetic progression.

The total number of queries must not exceed 2n2n. After finishing the interaction, output the answer immediately.

Interaction:

Input the sequence length nn and the query limit qq 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 11 meaning >> or 00 meaning <<. The query format is > x y.

For the second type of query, the interactive library returns a positive integer AiA_i. 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 dd.

3 6
1
2
3
? 1
? 2
? 3
! 1

Hint

For 50%50\% of the testdata, it is guaranteed that q=2nq=2n.

For the other 50%50\% of the testdata, it is guaranteed that q=2q=2.

For 100%100\% of the testdata, it is guaranteed that 2n1000002\leq n\leq 100000, 0Ai<p0\leq A_i< p, 1d<p1\le d < p.

Translated by ChatGPT 5