#P10032. Sequence Transformation by Global Mex Operations
Sequence Transformation by Global Mex Operations
Sequence Transformation by Global Mex Operations
Note the special time constraints for this problem.
You are given a sequence \(a\) of length \(n\) and an integer \(m\). An operation is defined as follows: simultaneously, for every element \(a_i\) of the sequence, replace it with the \(\operatorname{mex}\) of the sequence that results from removing \(a_i\) from \(a\). In other words, for every index \(i\), update
\[ a_i := \operatorname{mex}(a_1, a_2, \dots, a_{i-1}, a_{i+1}, \dots, a_n), \]where the \(\operatorname{mex}\) (minimum excludant) of a sequence is defined as the smallest non-negative integer not present in the sequence. For example:
- \(\operatorname{mex}\{1,2,3\} = 0\);
- \(\operatorname{mex}\{0\} = 1\);
- \(\operatorname{mex}\{1,0,2,4\} = 3\);
- \(\operatorname{mex}\{2,1,3,0,2\} = 4\).
In particular, the \(\operatorname{mex}\) of an empty sequence is defined to be \(0\).
Your task is to determine the final sequence after applying the above operation exactly \(m\) times. Note that due to the simultaneous nature of the operations, each new element in the sequence is computed based on the original array from that iteration.
Hint: Due to potential cycles or fixed points in the transformation process, you may need to perform cycle detection to efficiently compute the final sequence under strict time constraints.
inputFormat
The first line contains two integers \(n\) and \(m\) separated by a space.
The second line contains \(n\) integers representing the sequence \(a\), separated by spaces.
outputFormat
Output the final sequence after \(m\) operations. The numbers should be separated by a single space.
sample
3 1
1 2 3
0 0 0