#P9770. [HUSTFC 2023] 逆 KMP
[HUSTFC 2023] 逆 KMP
Problem Description
Walk Alone is a master of strings, but he has become bored with traditional string algorithms such as the KMP algorithm, so recently he has been thinking about a reversed version of KMP. Here is the problem he proposed:
You are given an integer sequence of length . For any integer , it satisfies . You need to construct another integer sequence that satisfies the following conditions:
- The sequence has length , and every element satisfies .
- For all integers and , it holds that .
- Under the above conditions, the number of distinct elements appearing in sequence is as large as possible.
Of course, Walk Alone can solve this problem easily, but he wants to use it as a test for you.
Input Format
The first line contains an integer , which denotes the length of sequence .
The second line contains integers, where the -th integer is defined as .
Output Format
Output integers separated by spaces, where the -th integer is defined as . If there are multiple valid answers, output the lexicographically smallest one.
5
0 0 1 2 3
1 2 1 2 1
11
0 0 0 0 2 1 0 0 3 0 1
1 2 3 1 2 1 1 2 3 4 1
Hint
Translated by ChatGPT 5