#P6823. 「EZEC-4」paulzrm Loves Array

「EZEC-4」paulzrm Loves Array

Description

Xiao Z has a sequence of length nn with indices starting from 11. Initially, the number at position ii is ii. There are mm operations, and 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 xx and yy. It is guaranteed that xyx\ne y and 1x,yn1\le x,y\le n.
  • 4 Reverse the sequence.

You need to output the sequence after mm operations.

Input Format

The first line contains two integers n,mn,m, representing the length of the sequence and the number of operations.

The next mm lines each contain one operation. It is guaranteed that all operations are valid.

Output Format

Output one line containing nn integers, representing the sequence after all operations.

5 5
1
2
3 2 4
4
3 1 5
5 4 3 2 1

Hint

Constraints

This problem uses bundled testdata.

subtask 1 (24 pts): 1n,m2×1031\le n,m\le 2\times 10^3.

subtask 2 (13 pts): There is no operation of type 3.

subtask 3 (63 pts): 1n,m1061\le n,m\le 10^6.

Sample Explanation

The operations applied to the sequence are:

1,2,3,4,51, 2, 3, 4, 5
1,2,3,4,51, 2, 3, 4, 5
5,4,3,2,15, 4, 3, 2, 1
5,2,3,4,15, 2, 3, 4, 1
1,4,3,2,51, 4, 3, 2, 5
5,4,3,2,15, 4, 3, 2, 1

Translated by ChatGPT 5