#P16192. [COI 2018] Zagonetka 谜题

    ID: 18105 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2018交互题Special JudgeCOI(克罗地亚)

[COI 2018] Zagonetka 谜题

Background

3 s, 1024 MB.

Problem Description

Mislav and Marin learned about permutations in a combinatorics class, and they invented an interesting game: the player needs to guess permutations that satisfy certain conditions. A permutation of order nn is an array p=(p1,p2,…,pn)p = (p_1, p_2, \ldots, p_n) in which each number from 11 to nn appears exactly once. A condition is a pair of distinct numbers (a,b)(a, b), both between 11 and nn. A permutation pp satisfies the condition (a,b)(a, b) if and only if pa<pbp_a < p_b.

The game works as follows: Marin first chooses zero or more conditions, and a permutation pp that satisfies all of them. When the game starts, Marin tells Mislav only this permutation pp (the conditions are kept secret). Mislav’s goal is to find the lexicographically smallest and the lexicographically largest permutations among all permutations that satisfy the conditions. In each step, Mislav chooses a permutation qq and sends it to Marin, and Marin tells him whether qq satisfies all the secret conditions.

This is an interactive task. Write a program to play this game on behalf of Mislav. Given a permutation pp (of length at most 100100) that satisfies the secret conditions, your program may make at most 50005000 queries to find the lexicographically smallest and the lexicographically largest permutations that satisfy all conditions.

Input Format

Interaction

At the beginning of the interaction, your program must read the following from standard input: the first line contains an integer nn, the order of all permutations in the game. The next line contains nn distinct integers p1,p2,…,pn (1≤pj≤n)p_1, p_2, \ldots, p_n\ (1 \le p_j \le n), representing the permutation pp. You may assume that pp satisfies all conditions chosen by Marin.

After that, your program can send queries to Marin. For each query, output one line in the format query q1 q2 ... qnq_1\ q_2\ ...\ q_n, where q1,q2,…,qnq_1, q_2, \ldots, q_n are distinct integers from 11 to nn. After each query, you must flush the output buffer, and then read Marin’s reply from standard input: if the permutation qq satisfies all conditions, the reply is 11, otherwise it is 00.

When your program has found the answer, output one line end, then output one line containing the lexicographically smallest permutation a1 a2 … ana_1\ a_2 \ \ldots\ a_n, and then output one line containing the lexicographically largest permutation b1 b2… bnb_1\ b_2 \ldots \ b_n. Finally, flush the output and terminate.

Note: the judging system provides sample code that demonstrates how to interact correctly and flush the output.

Hint

Example

In the following interaction example, the left column is what your program outputs to standard output, and the right column is what it reads from standard input. After three queries, the program found the correct answer.

Output Input Explanation
4 The secret conditions are (2,1)(2, 1) and (3,4)(3, 4)
3 2 1 4
query 2 3 1 4 0 Condition (2,1)(2, 1) is not satisfied
query 3 2 4 1 Condition (3,4)(3, 4) is not satisfied
query 4 1 2 3 1 Both conditions are satisfied
end
2 1 3 4
4 3 1 2

Subtasks

::cute-table{three} |ID |Score |Constraints | |:-:|:--:|:--------:| |11|99 |2≤n≤62 \le n \le 6| |22|1818|30≤n≤7030 \le n \le 70, Marin chose only 11 condition| |33|2222|10≤n<3010 \le n < 30| |44|5151|70<n≤10070 < n \le 100|

Translation source: GPT 4.1 mini.

Translated by ChatGPT 5