#P17038. [NWERC 2021] Boredom Buster

[NWERC 2021] Boredom Buster

Problem Description

You are stuck alone in a cabin and it is raining outside. You are bored out of your mind and the only available boredom buster is a deck of Memory cards. Playing Memory by yourself is not very fun, but you developed a single player variant that requires not only good memory but also strategy.

It goes like this: You have a shuffled deck of nn cards, where nn is even and each card contains a number from 11 to n2\frac{n}{2}. There are exactly two cards of each number. The cards are laid face down on the table and your goal is to find what number is written on each of them.

In one move, you pick up two cards. Before revealing them, you randomly shuffle them so that you do not know which card was where. Then you look at the two cards. After that, you shuffle them again face down before you put them back where they were. That way, you know the numbers of the two cards and where they are, but not which card ended up where, or even what card came from which spot initially.

Your task is to write a program that will beat this game.

Interaction

This is an interactive problem. Your submission will be run against an interactor, which reads the standard output of your submission and writes to the standard input of your submission. This interaction needs to follow a specific protocol:

  • The interactor first sends an integer nn (2n1052 \leq n \leq 10^5, nn is even). The only time nn is not equal to 10510^5 is in the sample.
  • Your submission then repeatedly sends two integers xx and yy (1x,yn1 \leq x, y \leq n, xyx \neq y) preceded by ?.
  • The interactor replies with two integers aa and bb (1a,bn21 \leq a, b \leq \frac{n}{2}), indicating that after the query either the xxth card is aa and the yyth card is bb, or the xxth card is bb and the yyth card is aa.
  • When you are ready to print the answer, print ! followed by nn integers a1,a2,,ana_1, a_2, \ldots, a_n, where aia_i is the number of the iith card at the time of writing.

You may use at most 9200092\,000 moves. Printing the answer does not count as a move.

The interactor is not adaptive. Initial positions of the cards are determined by the interactor before any interaction takes place. When you make a move the two cards will be shuffled uniformly randomly by the interactor both before being shown to you and before being placed back down. The initial layout of the cards is guaranteed to be a random permutation of 1,1,2,2,,n2,n21,1,2,2,\ldots,\frac{n}{2},\frac{n}{2}.

Your submission will be run on exactly 100100 test cases, each of which will have n=105n=10^5.

Make sure you flush the buffer after each write. A testing tool is provided to help you develop your solution.

Interaction Sample #1

In this sample, Sample Input contains the messages sent by the interactor to the submission, and Sample Output contains the messages sent by the submission to the interactor. They occur alternately in the order shown by the original interaction transcript.

6
3 2 
2 3 
1 1 
3 3 
? 2 1
? 5 3
? 6 4
? 1 3
! 3 2 3 1 2 1