#P7118. Permutation

    ID: 5975 远端评测题 7000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>“红旗杯”第十五届东北地区大学生程序设计竞赛

Permutation

Problem Description

Given $\{a_i\}$, a permutation of $1...n$, you need to perform the following operations:


  • Reverse a subarray indexed by $[L,R](1\le L\le R \le |a|)$, that is, $\forall i\in [L,\frac{L + R}{2}]$, $\texttt{swap(a[i],a[R+L-i])}$.

  • Complement the elements $a_i$ such that $L\le a_i\le R(1\le L\le R \le |a|)$, that is, $\forall L\le a_i\le R$, assign $\texttt{R+L-a[i]}$ to $\texttt{a[i]}$.

  • Increase all the elements that is no less than $v(1\le v\le |a|+1)$ by $1$, and then insert $v$ before the $i(1\le i\le |a|)$th element. It's clear that the array becomes a permutation of $1...|a|+1$ after that.

  • Given $i(1\le i\le |a|)$, print the value of $a_i$.

  • Given $v(1\le v\le |a|)$, print the position of $v$.

Input

This problem contains multiple test cases.

The first line contains a single integer $T$($1 \leq T \leq 10$), the number of test cases.

Each test case starts with a line of two integers $n,m(1\le n,m\le 10^5)$, the initial length of the permutation and the number of operations.

Then follows a line of $n$ numbers, representing a permutation of $1...n$.

For the following $m$ lines, each line is of the following format:


  • $\texttt{1 L R}$, asking you to reverse a subarray.

  • $\texttt{2 L R}$, asking you to complement certain elements.

  • $\texttt{3 i v}$, asking you to insert an element.

  • $\texttt{4 i}$, asking you to print the value of the $i$th element.

  • $\texttt{5 v}$, asking you to print the position of $v$.

Output

For each print operation, print a single integer in a line denoting the answer.

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