#P6823. 「EZEC-4」paulzrm Loves Array

「EZEC-4」paulzrm Loves Array

Background

Original statement:

zrmpaul\color{gray}\text{zrmpaul} has an array consisting of nn integers: a1,a2,...,ana_1,a_2,...,a_n. The initial value of aia_i is i(1in)i(1\le i\le n). There are mm operations, including four types as follows.

Type 11: 1 sort the array.
Type 22: 2 sort the array and reverse it.
Type 33: 3 x y swap ax,aya_x,a_y. It is guaranteed that xx is not equal to yy, and 1x,yn1\leq x ,y \leq n.
Type 44: 4 reverse the array.

You need to output the array after mm operations.

First line with two intergers n,m(1n,m106)n,m(1\leq n,m\leq 10^6).

Next mm lines are the operations.

One line, nn numbers, the array.

Problem 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