#P6823. 「EZEC-4」paulzrm Loves Array

「EZEC-4」paulzrm Loves Array

题目背景

原题面:

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.

题目描述

小 Z 有一个下标从 11 开始并且长度为 nn 的序列,初始时下标为 ii 位置的数字为 ii。有 mm 个操作,每个操作会是以下四种之一。

  • 1 对序列从小到大进行排序。
  • 2 对序列从小到大进行排序后将其翻转,(译者注:就是从大到小排序)。
  • 3 x y 将下标为 x,yx,y 的数交换位置。保证 xyx\neq y1x,yn1\le x,y\le n
  • 4 将序列翻转。

你要输出在 mm 次操作后的序列。

输入格式

第一行两个整数 n,mn,m ,表示序列的长度以及操作的数量。

接下来 mm 行,每行一个操作。保证操作合法。

输出格式

一行包含 nn 个整数,表示操作后的序列。

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

提示

【数据范围】

【本题采用捆绑测试】

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

subtask 2(13pts): 没有操作三。

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

【样例解释】

序列经过的操作为:

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