Limits 3s, 512 MB

Naruto Uzumaki is one of the strongest ninja of RUET (Rasengan University of Ebisu and Tobi), possessing unnaturally huge amount of chakra (a kind of energy). Due to this, he can create a lot of shadow clones (duplicates of himself) with his Shadow Clone Jutsu. Right now, Naruto is bored so he’s just playing around with his shadow clones.

Naruto has already created NN shadow clones and lined them up in a row. The ii-th clone has CiC^i amount of chakra in it. Naruto can do the following operations in his whim.

  1. Add VV: Makes a new shadow clone with V amount of chakra and adds him to the end of the line.
  2. Remove: Destroys the last shadow clone of the line.
  3. Query LL RR KK – Finds the shadow clone with KK-th largest chakra in [L,R][L, R] range i.e. the KK-th shadow clone if you sort the clones with position between L and R in the line according to their chakra in descending order.

Being a big fan of Naruto, you want to make a video game on Naruto following these 3 operations. In this problem, you have to do exactly that.

Input

The first line contains one integer NN (1N1051 \le N \le 10^5), the number of shadow clones that has been already created. The next line contains NN space separated integers denoting an array AA (1A[i]1091 ≤ A[i] ≤ 10^9). Then there will be an integer QQ (1Q1051 \le Q \le 10^5) - the number of operation Naruto performs. Then next QQ lines contains one of the following types:

  • 1 V\texttt{1 V}: Add a shadow clone with VV (1V1091 \le V \le 10^9) amount chakra to the end of the line
  • 2\texttt{2}: Destroys the last shadow clone of the line
  • 3 L R K\texttt{3 L R K}: Finds the shadow clone with KK-th (1KRL+11 \le K \le R-L+1) largest chakra in [L,R][L, R] (1L,RTotal Number of Current Shadow Clones1 \le L, R \le \texttt{Total Number of Current Shadow Clones}) range i.e. the KK-th shadow clone if you sort the clones with position between LL and RR in the line according to their chakra in descending order. It is guaranteed that shadow clones will always exist in [L,R][L, R] range.

Output

For each 3rd type of operation you have to print a single integer that denotes the KK-th largest chakra in [L,R][L, R] range.

Sample

InputOutput
3
7 3 5 
7
3 1 3 2
1 10
3 1 4 2
2
2
1 1
3 2 3 2
5
7
1

Submit

Login to submit.

Contributors

Statistics

76% Solution Ratio
YouKnowWhoEarliest, Aug '19
mdshadeshFastest, 0.0s
mdshadeshLightest, 75 kB
mumith_fahim99Shortest, 1946B
Toph uses cookies. By continuing you agree to our Cookie Policy.