F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Permutation

Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 24    Accepted Submission(s): 4


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.
 

Sample Input
1 5 5 1 2 3 4 5 1 1 3 2 1 5 3 1 2 4 6 5 2
 

Sample Output
1 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 07:10:38, Gzip enabled