1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 20000+100
14 #define maxm 5000000+1000
15 #define eps 1e-10
16 #define pa pair<int,int>
17 #define for0(i,n) for(int i=0;i<=(n);i++)
18 #define for1(i,n) for(int i=1;i<=(n);i++)
19 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
20 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
21 #define mod 1000000007
22 using namespace std;
23 inline int read()
24 {
25 int x=0,f=1;char ch=getchar();
26 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
27 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
28 return x*f;
29 }
30 int n,m,tot,top,cnt;
31 int a[maxn],num[maxn],hash[maxn];
32 int flag[maxn],ql[maxn],qr[maxn],rk[maxn],root[maxn];
33 int sum[maxm],ls[maxm],rs[maxm];
34 int ll[30],rr[30];
35 void update(int l,int r,int x,int &y,int v,int d)
36 {
37 y=++cnt;
38 sum[y]=sum[x]+d;
39 if(l==r)return;
40 ls[y]=ls[x];rs[y]=rs[x];
41 int mid=(l+r)>>1;
42 if(v<=mid)update(l,mid,ls[x],ls[y],v,d);else update(mid+1,r,rs[x],rs[y],v,d);
43 }
44 void change(int x,int y,int z)
45 {
46 for(;x<=tot;x+=x&(-x))update(1,tot,root[x],root[x],y,z);
47 }
48 int query(int l,int r,int k)
49 {
50 if(l==r)return l;
51 int suml=0,sumr=0;
52 for1(i,ll[0])suml+=sum[ls[ll[i]]];
53 for1(i,rr[0])sumr+=sum[ls[rr[i]]];
54 int mid=(l+r)>>1;
55 if(sumr-suml>=k)
56 {
57 for1(i,ll[0])ll[i]=ls[ll[i]];
58 for1(i,rr[0])rr[i]=ls[rr[i]];
59 return query(l,mid,k);
60 }
61 else
62 {
63 for1(i,ll[0])ll[i]=rs[ll[i]];
64 for1(i,rr[0])rr[i]=rs[rr[i]];
65 return query(mid+1,r,k-(sumr-suml));
66 }
67 }
68 int main()
69 {
70 freopen("input.txt","r",stdin);
71 freopen("output.txt","w",stdout);
72 char s[3];
73 n=read();m=read();
74 for1(i,n)num[++top]=a[i]=read();
75 for1(i,m)
76 {
77 scanf("%s",s);
78 ql[i]=read();qr[i]=read();
79 if(s[0]==‘Q‘){rk[i]=read();flag[i]=1;}
80 else num[++top]=qr[i];
81 }
82 sort(num+1,num+top+1);
83 hash[++tot]=num[1];
84 for2(i,2,top)
85 if(num[i]!=num[i-1])
86 hash[++tot]=num[i];
87 for1(i,n)a[i]=lower_bound(hash+1,hash+tot+1,a[i])-hash;
88 for1(i,n)change(i,a[i],1);
89 for1(i,m)
90 if(flag[i])
91 {
92 ll[0]=rr[0]=0;ql[i]--;
93 for(int j=ql[i];j;j-=j&(-j))ll[++ll[0]]=root[j];
94 for(int j=qr[i];j;j-=j&(-j))rr[++rr[0]]=root[j];
95 printf("%d\n",hash[query(1,tot,rk[i])]);
96 }
97 else
98 {
99 change(ql[i],a[ql[i]],-1);
100 a[ql[i]]=lower_bound(hash+1,hash+tot+1,qr[i])-hash;
101 change(ql[i],a[ql[i]],1);
102 }
103 return 0;
104 }