#P6823. Sequence Operations Simulation
Sequence Operations Simulation
Sequence Operations Simulation
You are given a sequence with indices starting from \(1\) and of length \(n\), where initially the integer at index \(i\) is \(i\). There are \(m\) operations to perform on this sequence. Each operation is one of the following four types:
- 1: Sort the sequence in increasing order.
- 2: Sort the sequence in increasing order and then reverse it (i.e. sort in decreasing order).
- 3 \(x\ y\): Swap the numbers at indices \(x\) and \(y\). It is guaranteed that \(x \neq y\) and \(1 \le x, y \le n\).
- 4: Reverse the sequence.
After performing the \(m\) operations in order, output the final sequence.
inputFormat
The first line contains two integers \(n\) and \(m\) (the length of the sequence and the number of operations).
The next \(m\) lines each describe an operation in one of the following formats:
- 1
- 2
- 3 x y
- 4
Note that for an operation of type 3, \(x \neq y\) and \(1 \le x, y \le n\).
outputFormat
Output the final sequence after all operations have been performed. The numbers should be printed in order and separated by spaces.
sample
5 3
4
3 1 5
1
1 2 3 4 5