# bzoj1901Zju2112 Dynamic Rankings

http://www.elijahqi.win/archives/1733
Description

],a[i+2]……a[j]中第k小的数是多少(1≤k≤j-i+1)，并且，你可以改变一些a[i]的值，改变后，程序还能针对改

Input

Q i j k 或者 C i t
Q i j k （i,j,k是数字，1≤i≤j≤n, 1≤k≤j-i+1）

C i t (1≤i≤n，0≤t≤10^9)表示把a[i]改变成为t
m,n≤10000
Output

Sample Input
5 3

3 2 1 4 7

Q 1 4 3

C 2 6

Q 2 5 3

Sample Output
3

6

#include<cstdio>
#include<algorithm>
#define N 11000
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S) {T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
int x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
return x*f;
}
struct node{
int l,r,k;
}qr[N];
struct node1{
int left,right,v;
}tree[N*400];
int n,m,nn,b[N<<1],a[N],ss[N],ll[N],rr[N],ln,rn,num,root[N<<1],a1[N<<1];
inline void insert1(int &x,int l,int r,int p,int v){
tree[++num]=tree[x];x=num;tree[x].v+=v;
if (l==r) return;int mid=l+r>>1;
if (p<=mid) insert1(tree[x].left,l,mid,p,v);else insert1(tree[x].right,mid+1,r,p,v);
}
inline void add(int x,int v){for (int i=x;i<=n;i+=i&(-i)) insert1(root[i],1,nn,a1[x],v);}
int query(int l,int r,int k){
if (l==r) return l;int mid=l+r>>1,size=0;
for (int i=1;i<=ln;++i) size-=tree[tree[ll[i]].left].v;
for (int i=1;i<=rn;++i) size+=tree[tree[rr[i]].left].v;
if (k<=size){
for (int i=1;i<=ln;++i) ll[i]=tree[ll[i]].left;for (int i=1;i<=rn;++i) rr[i]=tree[rr[i]].left;return query(l,mid,k);
}else{
for (int i=1;i<=ln;++i) ll[i]=tree[ll[i]].right;for (int i=1;i<=rn;++i) rr[i]=tree[rr[i]].right;return query(mid+1,r,k-size);
}
}
int main(){
freopen("bzoj1901.in","r",stdin);
for (int i=1;i<=m;++i){char ch=gc();
}sort(b+1,b+cnt+1);nn=unique(b+1,b+cnt+1)-b-1;
for (int i=1;i<=m;++i){
if (qr[i].k){
ln=rn=0;for (int j=qr[i].l-1;j;j-=j&(-j)) ll[++ln]=root[j];
for (int j=qr[i].r;j;j-=j&(-j)) rr[++rn]=root[j];printf("%d\n",b[query(1,nn,qr[i].k)]);
}else{
}