#P7329. 「MCOI-07」Dream and More Discs

「MCOI-07」Dream and More Discs

Description

Dream divides all of Tommy's music discs into nn categories. In the ii-th category, there are 2m12^m - 1 music discs. Each disc has a unique positive integer importance value.
Now Dream has sorted the discs within each category in increasing order of importance. Dream wants to know which disc has the kk-th smallest importance among all discs.

Because there are too many music discs, Dream cannot directly give you the importance of every disc. While searching for the answer, Dream allows you to query the importance value of the disc that is the jj-th smallest in the ii-th category.

Input Format

At the beginning of the interaction, the judge inputs four positive integers nn, mm, kk, and ThTh on the first line, where ThTh is the maximum number of queries allowed.
For each query, the judge will reply with the importance value of the disc at the queried position.

Output Format

Your program can perform two operations:

  1. ? i j, which queries the importance of the jj-th smallest disc in category ii. The judge will reply with the importance value at this position.
  2. ! i j, which reports that the globally kk-th smallest disc is the jj-th smallest disc in category ii.
2 2 2 22

222

? 2 2

! 2 2

Hint

Explanation for Sample 1

Dream's disc importance values are [[2222,22222,222222],[22,222,2222222]][[2222,22222,222222],[22,222,2222222]].
Category 2 is [22,222][22,222]; the 2nd smallest importance in category 2 is 222222.
The globally 2nd smallest importance is also this disc.

Constraints

This problem uses bundled testdata.

Subtask Score nn mm kk ThTh
1 1 pts 11 15,00015,000
2 9 pts 5050 88 None
3 19 pts 2020 1111
4 17 pts 5050 6,6666,666
5 23 pts 2,3332,333
6 31 pts 1,1111,111

For all testdata, 1kn(2m1)1 \le k \le n(2^m - 1). All disc importance values are pairwise distinct and are at most 101810^{18}.

Translated by ChatGPT 5