#P48. [KBC003Ex] Sequence 4

[KBC003Ex] Sequence 4

Source

This problem is adapted from Long Long OJ. All rights reserved.

Attention

The time limit for this problem is 10 seconds.

Problem Description

Given a sequence a1,a2,,ana_1,a_2,\ldots,a_n containing nn elements, perform qq operations:

  • Query (Type 1): Formatted as 1 x y\texttt{1 x y}, which means output ax,ax+1,,aya_x,a_{x+1},\cdots,a_y in sequence. It is guaranteed that 1yx+1201\le y-x+1\le 20.
  • Move (Type 2): Formatted as 2 x y\texttt{2 x y}, which means move axa_x to the position right after aya_y. It is guaranteed that 1x<yn1\le x < y \le n.
  • Cut and Reverse (Type 3): Formatted as 3 x y\texttt{3 x y}, which means cut the subsequence ax,ax+1,,aya_x,a_{x+1},\cdots,a_y, reverse it, and append it to the end of the original sequence. It is guaranteed that 1x<yn1\le x < y \le n.
  • Modify (Type 4): Formatted as 4 x y\texttt{4 x y}, which means update axa_x to yy (i.e., axya_x \leftarrow y). It is guaranteed that 1xn1\le x \le n and 109y109-10^9\le y\le 10^9.

Input Format

  • The first line contains two integers nn and qq, representing the length of the sequence and the number of queries respectively;
  • The second line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n;
  • Lines 33 to q+2q+2 each contain one query.

Output Format

For each Query (Type 1) operation, output a line containing yx+1y-x+1 integers separated by spaces.

In particular, after all operations on the sequence are completed, output a line containing nn integers, with the specific format shown below:

Final sequence: a[1] a[2] ... a[n]

Samples

Download the sample files from the link below.

Attachments

Download the files here.

Data Range

The information for each test case is shown in the table below (this problem does not use bundled testing):

Test Case ID Belongs to Subtask 0n,q\bm {0\le n,q \le} Special Properties
11 00 //
22 11 1010 A\mathcal A
33 22 500500
44
55
66 33 50005000
77
88
99
1010
1111 //
1212
1313 44 200000200000 A,B\mathcal {A,B}
1414 55 A,C\mathcal {A,C}
1515
1616 66 A,D\mathcal {A,D}
1717
1818 D\mathcal D
1919
2020
2121 77 A\mathcal A
2222 //
2323
2424
2525
  • Special Property A\mathcal A: The data is random.
  • Special Property B\mathcal B: Only Query (Type 1) and Modify (Type 4) operations are present.
  • Special Property C\mathcal C: Only Move (Type 2) operations are present.
  • Special Property D\mathcal D: Only Cut and Reverse (Type 3) operations are present.
  • Special Property /\mathcal /: No special properties.

For 100%100\% of the data, 1n,q2×1051\le n,q\le 2 \times 10^5 and 109ai109-10^9\le a_i\le 10^9.