배열을 두 부분으로 나눠 병합하는 연산을 처리하면서 특정 위치의 값을 출력하는 문제로, 병합이 두 부분을 정렬한다는 성질을 이용한다.
보통7배열이분 탐색시뮬레이션누적 합아직 제출이 없습니다시간 제한2초메모리 제한512 MBYou have an array a=(a_1,…,a_n) that initially contains a permutation of numbers 1 through n. You have to process queries of two types:
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 n and m --- the length of the array and the number of queries (2≤n,m≤2⋅105).
The second line contains n distinct integers a_1,a_2,…,a_n (1≤a_i≤n).
Each of the next m lines contains two integers t_i and p_i --- the description of the i-th query (t_i∈1,2, p satisfies the constraints given in the format description above).
For each query of type 1, print the answer on a separate line.