#P9741. Binary Sequence Transformation
Binary Sequence Transformation
Binary Sequence Transformation
Given a binary sequence \(a_1, a_2, \ldots, a_n\) of length \(n\), you must perform \(n\) operations sequentially. In the \(i\)-th operation (\(1 \le i \le n\)), perform the following two transformations:
- Reverse the subarray \([1, i]\): The sequence \(a_1, a_2, \ldots, a_i\) becomes \(a_i, a_{i-1}, \ldots, a_1\).
- Flip the bits in the subarray \([1, i]\): For every \(1 \le j \le i\), if \(a_j = 0\) it becomes \(1\), and if \(a_j = 1\) it becomes \(0\).
After executing all \(n\) operations, output the final state of the sequence.
inputFormat
The first line contains a single integer \(n\) (\(1 \le n \le 10^5\)), the length of the sequence.
The second line contains \(n\) space-separated integers, each either \(0\) or \(1\), representing the initial sequence \(a_1, a_2, \ldots, a_n\).
outputFormat
Output the final sequence after performing all the operations. Print \(n\) integers separated by a space.
sample
1
0
1
</p>