아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Halve & Merge

시간 제한2초메모리 제한512 MB

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

보통10점 중 7점

유형
배열, 이분 탐색, 시뮬레이션, 누적 합
정답자
아직 제출이 없습니다

문제

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" (1≤p≤n1 \leq p \leq n): find a_pa\_p in the current array aa;
  • "22 pp" (1≤p≤n−11 \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 (2≤n,m≤2⋅1052 \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 (1≤a_i≤n1 \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_i∈1,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.

예제2

  1. 예제 1

    입력
    4 3
    4 3 2 1
    2 1
    2 1
    1 2
    
    예상 출력
    1
    
  2. 예제 2

    입력
    5 7
    4 3 5 2 1
    2 4
    2 1
    1 3
    1 1
    2 4
    1 4
    1 5
    
    예상 출력
    3
    1
    3
    5