Under construction

Still being built. Things may change

Emission Spectrum

Time limit2sMemory limit512 MB

Summary
Maintain an integer array under adjacent swaps and answer k-th smallest value queries over subarrays online.
Level

Hard8 of 10

Topics
Binary search, Divide and conquer, Segment tree, Sorting
Solved
No attempts yet

Problem

Scientists at the Interstellar Consortium of Planets and Constellations (ICPC) study what celestial objects are made of by analyzing their emission spectrum. The emission spectrum of a celestial object is the set of frequencies of electromagnetic radiation emitted by its atomic energy transitions, together with the intensity of that radiation. It records how strong each color of the emitted light is.

By the postulates of quantum mechanics the emission spectrum of a celestial object is always discrete, so the ICPC stores a spectrum as a sequence of integers. Each position of the sequence is the intensity of one wavelength, a larger number means a stronger emission, and neighboring positions of the sequence are neighboring wavelengths of the spectrum.

An emission spectrum is the result of very complex physical processes, so it changes over the lifetime of the object. In particular, because of atomic reactions that are not yet fully understood, the intensities of two neighboring wavelengths can be swapped at some moment.

The ICPC is watching the spectrum of one celestial object very closely. Given a range of wavelengths and an integer KK, the scientists want the intensity of the wavelength with the KK-th smallest intensity in that range. You are given the observation log, which mixes the questions asked by the scientists with the intensity swaps that happen in the spectrum. Answer every question.

Input

The first line contains two integers NN and QQ, the number of measured wavelengths and the number of events (1≤N,Q≤1051 \le N, Q \le 10^5). The second line contains NN integers I1,I2,…,INI_1, I_2, \dots, I_N, where IiI_i is the initial intensity of the ii-th wavelength (0≤Ii≤1090 \le I_i \le 10^9).

Each of the next QQ lines describes one event and starts with a character giving the type of the event. A question from the scientists starts with the character Q, and an atomic swap reaction starts with the character S.

A question line has three integers AA, BB and KK after that character. The scientists ask for the KK-th smallest intensity among the wavelengths at positions AA through BB, inclusive (1≤A≤B≤N1 \le A \le B \le N, 1≤K≤B−A+11 \le K \le B - A + 1).

A swap line has one integer WW after that character. The intensities at positions WW and W+1W + 1 are exchanged (1≤W≤N−11 \le W \le N - 1).

Output

For each question print one line with a single integer, the KK-th smallest intensity among the wavelengths at positions AA through BB, inclusive. Answer the questions in the order they appear in the input.

Examples2

  1. Example 1

    Input
    10 4
    1 2 6 7 5 8 9 3 0 4
    Q 1 10 7
    Q 2 5 2
    S 5
    Q 2 5 2
    
    Expected output
    6
    5
    6
    
  2. Example 2

    Input
    4 3
    33333333 22222222 44444444 11111111
    Q 3 3 1
    S 1
    Q 2 4 2
    
    Expected output
    44444444
    33333333