#abc371g. G - Lexicographically Smallest Permutation
G - Lexicographically Smallest Permutation
Score : points
问题陈述
给定排列 和 ,它们都是 的排列。
你可以执行以下操作任意次数,包括零次:
- 同时将所有的 替换为 。
打印出可以获得的字典序最小的 。
什么是字典序?
对于长度为 的序列, 和 ,如果存在一个整数 使得 ,并且对于所有 ,,则称 字典序小于 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given permutations and of .
You can perform the following operation any number of times, possibly zero:
- replace with simultaneously for all .
Print the lexicographically smallest that can be obtained.
What is lexicographical order?
For sequences of length , and , is lexicographically smaller than if and only if:
- there exists an integer such that , and for all .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Let be the lexicographically smallest that can be obtained. Print in this order, separated by spaces, in one line.
Sample Input 1
6
3 1 5 6 2 4
4 3 1 6 2 5
Sample Output 1
1 4 2 5 3 6
Initially, .
Repeating the operation yields the following.
After this, will revert to the original state every four operations.
Therefore, print the lexicographically smallest among these, which is 1 4 2 5 3 6
.
Sample Input 2
8
3 5 8 7 2 6 1 4
1 2 3 4 5 6 7 8
Sample Output 2
1 2 3 4 5 6 7 8
You may choose to perform no operations.
Sample Input 3
26
24 14 4 20 15 19 16 11 23 22 12 18 21 3 6 8 26 2 25 7 13 1 5 9 17 10
15 3 10 1 13 19 22 24 20 4 14 23 7 26 25 18 11 6 9 12 2 21 5 16 8 17
Sample Output 3
4 1 22 18 20 13 14 6 15 11 3 26 2 12 5 23 9 10 25 24 7 17 16 21 19 8