eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Commuting Functions

Commuting Functions

\includegraphics{https://static.e-olymp.com/content/a0/a01d6fe5baf86fd274dfc5600a30f76cc672dd3c.jpg} Two functions \textbf{f} and \textbf{g} (\textbf{f}, \textbf{g}: \textbf{X} → \textbf{X}) are \textit{commuting} if and only if \textbf{f(g(x)) = g(f(x))} for each \textbf{xX}. For example, functions \textbf{f(x) = x+1} and \textbf{g(x) = x-2} are commuting, whereas functions \textbf{f(x) = x+1} and \textbf{g(x) = 2x} are not commuting. \includegraphics{https://static.e-olymp.com/content/c3/c3a83fad593a4565b94f49e32e109a80649d0f7b.jpg} \includegraphics{https://static.e-olymp.com/content/d5/d5dd011396666338e3c5338319465f522ec75fc5.jpg} Each function \textbf{h} (\textbf{h: N_n} → \textbf{N_n}, where \textbf{N_n = \{1, 2, ..., n\}} and \textbf{n} is positive integer) can be represented as a \textit{value list} - a list in which the \textbf{i}-th element is equal to \textbf{h(i)}. For example, a function \textbf{h(x) = x/2} from \textbf{N_5} to \textbf{N_5} has the value list \textbf{\[1, 1, 2, 2, 3\]}. The value lists are ordered lexicographically: list \[\textbf{a_1} ... \textbf{a_n}\] is smaller than list \[\textbf{b_1} ... \textbf{b_n}\] if and only if there exists such an index \textbf{k} that \textbf{a_k} < \textbf{b_k}, and \textbf{a_l} = \textbf{b_l} for any index \textbf{l} < \textbf{k}. The function \textbf{f} (\textbf{f : X }→\textbf{ X}) is \textit{bijective} if for every \textbf{y} in \textbf{X}, there is exactly one \textbf{x} in \textbf{X} such that \textbf{f(x) = y}. Given a bijective function \textbf{f} (\textbf{f: N_n }→\textbf{ N_n}, \textbf{n} is positive integer), find the function \textbf{g} that is commuting with \textbf{f} and has the lexicographically smallest possible value list. \InputFile The first line contains single integer number \textbf{n} - the number of the elements in the value list of bijective function \textbf{f} (\textbf{1} ≤ \textbf{n} ≤ \textbf{200000}). The second line of the input file contains the value list of the function \textbf{f}. \OutputFile The single line of the output file must contain \textbf{n} integer numbers - the value list of function \textbf{g} that commutes with the function \textbf{f} and has the lexicographically smallest value list.
Лимит времени 3 секунды
Лимит использования памяти 256 MiB
Входные данные #1
10
1 2 3 4 5 6 7 8 9 10
Выходные данные #1
1
1
1
1
1
1
1
1
1
1
Автор Dvorkin,Shtukenberg,Korneev