Bubble Sort Machine
시간 제한2초메모리 제한2048 MB
수열에 왼쪽부터 훑는 버블 정렬 패스를 반복로 적용하면서, 각 시점마다 구간 합을 답한다.
문제
JOI-kun, an algorithm researcher, has developed a machine called the Bubble Sort Machine.
The Bubble Sort Machine operates on an integer sequence of length . To activate the Bubble Sort Machine, the initial values are provided as input for each (). Each time Button 1 on the Bubble Sort Machine is pressed, the machine modifies the sequence in the following way:
- For each in order, if , then the values of and are swapped.
To make the Bubble Sort Machine even more appealing, JOI-kun decided to add the following feature:
- When Button 2 is pressed and integers and satisfying are given as input, the machine outputs the value of .
Given the initial values of the integer sequence and the sequence of operations on the Bubble Sort Machine, write a program that computes the outputs produced by Button 2.
입력
Read the following data from the standard input.
(Query )
(Query )
(Query )
Here, is the number of operations performed on the Bubble Sort Machine. Each (Query ) () consists space separated integers. Let denote the first integer of (Query ). The content of this line is one of the following.
- If , this line contains no additional integers. This means that the -th operation on the Bubble Sort Machine is pressing Button 1.
- If , this line contains two more integers, and , in that order. This means that the -th operation on the Bubble Sort Machine is pressing Button 2 with the integers and as input.
출력
For each operation where Button 2 is pressed, that is, for each () such that , output the integer produced by the Bubble Sort Machine on a separate line in the order of the queries.
제한
- .
- ().
- .
- is either or ().
- If , ().
- Given values are all integers.