CF BUDDY
← Problems·

1815B · Sum Graph

2000 · brute force, constructive algorithms, graphs

Problem: This is an interactive problem.

There is a hidden permutation p1,p2,,pnp_1, p_2, \dots, p_n.

Consider an undirected graph with nn nodes only with no edges. You can make two types of queries:

  1. Specify an integer xx satisfying 2x2n2 \le x \le 2n. For all integers ii (1in1 \le i \le n) such that 1xin1 \le x-i \le n, an edge between node ii and node xix-i will be added.
  2. Query the number of edges in the shortest path between node pip_i and node pjp_j. As the answer to this question you will get the number of edges in the shortest path if such a path exists, or 1-1 if there is no such path.

Note that you can make both types of queries in any order.

Within 2n2n queries (including type 11 and type 22), guess two possible permutations, at least one of which is p1,p2,,pnp_1, p_2, \dots, p_n. You get accepted if at least one of the permutations is correct. You are allowed to guess the same permutation twice.

A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

Input Format: Each test contains multiple test cases. The first line contains a single integer tt (1t1001 \le t \le 100) — the number of test cases.

The first line of each test case contains a single integer nn (2n1032 \le n \le 10^3) — the length of the permutation.

It is guaranteed that the sum of nn over all test cases does not exceed 10310^3.

Note: In the first test case, n=6n=6 and the hidden permutation p=[1,4,2,5,3,6]p = [1,4,2,5,3,6].

Firstly, make a type 11 query on x=12,2,3x=12, 2, 3 respectively. This adds four edges to the graph in total:

  • An edge that connects node 66 and node 66.
  • An edge that connects node 11 and node 11.
  • An edge that connects node 11 and node 22.
  • An edge that connects node 22 and node 11.

Since all of these queries are valid, the interactor returns 11 after each of them.

Then, query the number of edges in the shortest path between node p1=1p_1 = 1 and p3=2p_3 = 2, which is equal to 11.

Then, make a type 11 query on x=5x=5. This adds four edges to the graph in total:

  • An edge that connects node 11 and node 44.
  • An edge that connects node 22 and node 33.
  • An edge that connects node 33 and node 22.
  • An edge that connects node 44 and node 11.

Since this query is valid, the interactor returns 11.

Then, query the number of edges in the shortest path between node p1=1p_1 = 1 and p5=3p_5 = 3, which is equal to 22.

Then, query the number of edges in the shortest path between node p4=5p_4 = 5 and p5=3p_5 = 3. Such a path doesn't exist, therefore the interactor returns 1-1.

Afterwards, due to some magic, two possible permutations that can be pp are determined: the first permutation is [1,4,2,5,3,6][1,4,2,5,3,6] and the second permutation is [1,2,3,4,5,6][1,2,3,4,5,6]. Since the first permutation is equal to the hidden permutation, this test case is solved correctly. In total, 77 queries are used, which is within the limit of 26=122 \cdot 6 = 12 queries.

Since the answer is correct, the interactor returns 11.

In the second test case, n=2n=2 and the hidden permutation is p=[2,1]p = [2,1].

Since there are only 2!=22! = 2 possible permutations, no queries are needed. It is sufficient to just output the two permutations, [1,2][1,2] and [2,1][2,1]. In total, 00 queries are used, which is within the limit of 22=42 \cdot 2 = 4 queries.

Since the answer is correct, the interactor returns 11.

Sample Cases

Case 1

Input

2
6

1

1

1

1

1

2

-1

1
2

1

Output

+ 12

+ 2

+ 3

? 1 3

+ 5

? 1 5

? 4 5

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


! 1 2 2 1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback