#P9227. XOR Product Transformation
XOR Product Transformation
XOR Product Transformation
Given a sequence \(a = \{a_1, a_2, \ldots, a_n\}\), its XOR product is defined as a sequence \(b = \{b_1, b_2, \ldots, b_n\}\) where for each \(i\) we have
\(b_i = \bigoplus_{\substack{1 \le j \le n \\ j \ne i}} a_j\)
Here \(\oplus\) denotes the bitwise XOR operation. For example, the XOR product of \(\{1, 2, 3, 4\}\) is \(\{5, 6, 7, 0\}\).
An XOR product transformation replaces the sequence with its XOR product. Since the length remains the same, this process can be applied repeatedly. Specifically, if we denote \(T(a)\) as the XOR product transformation on sequence \(a\), then
\(T(a)_i = S \oplus a_i\) where \(S = a_1 \oplus a_2 \oplus \cdots \oplus a_n\).
It is known that:
- If \(n\) is even, then \(T(T(a)) = a\); hence the transformation is periodic with period 2.
- If \(n\) is odd, then \(T(a)\) is idempotent with \(T(T(a)) = T(a)\).
Your task is to compute the resulting sequence after applying the XOR product transformation \(k\) times on the given sequence \(a\).
inputFormat
The first line contains two integers \(n\) and \(k\) (where \(1 \le n \le 10^5\) and \(0 \le k \le 10^9\)).
The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (each \(a_i\) fits in a 32-bit integer) representing the initial sequence.
outputFormat
Output the resulting sequence after \(k\) XOR product transformations. Print the \(n\) numbers separated by spaces.
sample
4 1
1 2 3 4
5 6 7 0