Halve & Merge

배열을 두 부분으로 나눠 병합하는 연산을 처리하면서 특정 위치의 값을 출력하는 문제로, 병합이 두 부분을 정렬한다는 성질을 이용한다.

보통7배열이분 탐색시뮬레이션누적 합아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You have an array a=(a_1,,a_n)a = (a\_1, \ldots, a\_n) that initially contains a permutation of numbers 11 through nn. You have to process queries of two types:

  • "11 pp" (1pn1 \leq p \leq n): find a_pa\_p in the current array aa;
  • "22 pp" (1pn11 \leq p \leq n - 1): replace aa by the result of the function merge applied to arrays (a_1,,a_p)(a\_1, \ldots, a\_p) and (a_p+1,,a_n)(a\_{p + 1}, \ldots, a\_n).

Function merge can be written in the following way.

func merge(var a as array, var b as array)
     var c as array
     while (a and b have elements)
          if (a[0] > b[0])
               add b[0] to the end of c
               remove b[0] from b
          else
               add a[0] to the end of c
               remove a[0] from a
     while (a has elements)
          add a[0] to the end of c
          remove a[0] from a
     while (b has elements)
          add b[0] to the end of c
          remove b[0] from b
     return c

입력

The first line contains two integers nn and mm --- the length of the array and the number of queries (2n,m21052 \le n, m \le 2 \cdot 10^5).

The second line contains nn distinct integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n (1a_in1 \leq a\_i \leq n).

Each of the next mm lines contains two integers t_it\_i and p_ip\_i --- the description of the ii-th query (t_i1,2t\_i \in \\{1, 2\\}, pp satisfies the constraints given in the format description above).

출력

For each query of type 1, print the answer on a separate line.