logo AlgoBeat OnlineJudge
登录 注册

#210339. [ICPC 2024 Xi'an I] Guess The Tree

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There is a full binary tree with levels(so it has exactly nodes). Each node has an integer ID from to , and the IDs form an arrangement from to , but you don't know.

You need to find the IDs of the nodes using at most queries.

输入格式

The first line contains one integer , the levels of the full binary tree.

To ask a query, you need to pick two nodes with IDs , and print the line of the following form:

"? u v"

After that, you will receive:

"t"

The lowest common ancestor's ID of and .

You can ask at most queries.

If you have found the structure of the tree, print a line of the following form:

"! ... "

means the i-th node's father's ID. If it has no father, then .

After printing a query or the answer for a test case, do not forget to output the end of line and flush the output. Otherwise, you will get the verdict 'Idleness Limit Exceeded'. To do this, use:

fflush(stdout) or cout.flush() in C++;

System.out.flush() in Java;

stdout.flush() in Python.

The interactor in this task is not adaptive.

样例

样例输入 1

2

3

3

3

样例输出 1


? 1 2

? 2 3

? 1 3

! 3 3 -1

数据范围与提示

In this case, the tree's root is , it's two sons are and .

For any query "? a b",if , the jury will return answer .

So we found the tree's root is .