题意:带修改的区间第k大
题解:树状数组套主席树,开n个主席树,用树状数组维护,先离散化,然后动态开点按权值插入到树状数组访问到的节点,然后修改也是同样的修改,查询需要在主席树上二分,同时维护树状数组所访问的那些节点,在主席树上跑即可//#pragma GCC optimize(2)//#pragma GCC optimize(3)//#pragma GCC optimize(4)//#pragma GCC optimize("unroll-loops")//#pragma comment(linker, "/stack:200000000")//#pragma GCC optimize("Ofast,no-stack-protector")//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")#include#define fi first#define se second#define db double#define mp make_pair#define pb push_back#define pi acos(-1.0)#define ll long long#define vi vector #define mod 998244353#define ld long double//#define C 0.5772156649//#define ls l,m,rt<<1//#define rs m+1,r,rt<<1|1#define pll pair #define pil pair #define pli pair #define pii pair #define ull unsigned long long//#define base 1000000000000000000#define fin freopen("a.txt","r",stdin)#define fout freopen("a.txt","w",stdout)#define fio ios::sync_with_stdio(false);cin.tie(0)inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}template inline T const& MAX(T const &a,T const &b){return a>b?a:b;}template inline T const& MIN(T const &a,T const &b){return a >=1;}return ans;}inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}using namespace std;const ull ba=233;const db eps=1e-8;const ll INF=0x3f3f3f3f3f3f3f3f;const int N=200000+10,maxn=200000+10,inf=0x3f3f3f3f;int n,m,cnt;int qq[N],top=0;struct bit_seg{ int root[N],ls[N*50],rs[N*50],sum[N*50],res,te[2][20],num[2]; bit_seg(){res=0;} void update(int &o,int pos,int v,int l,int r) { if(!o) { if(top)o=qq[top--]; else o=++res; } sum[o]+=v; if(l==r)return ; int m=(l+r)>>1; if(pos<=m)update(ls[o],pos,v,l,m); else update(rs[o],pos,v,m+1,r); if(!sum[o])qq[++top]=o,o=0; } int query(int k,int l,int r) { if(l==r)return l; int m=(l+r)>>1,ans=0; for(int i=1;i<=num[1];i++)ans+=sum[ls[te[1][i]]]; for(int i=1;i<=num[0];i++)ans-=sum[ls[te[0][i]]];// printf("%d %d %d\n",l,r,ans); if(ans>=k) { for(int i=1;i<=num[1];i++)te[1][i]=ls[te[1][i]]; for(int i=1;i<=num[0];i++)te[0][i]=ls[te[0][i]]; return query(k,l,m); } else { for(int i=1;i<=num[1];i++)te[1][i]=rs[te[1][i]]; for(int i=1;i<=num[0];i++)te[0][i]=rs[te[0][i]]; return query(k-ans,m+1,r); } } int bitquery(int L,int R,int k) { num[0]=num[1]=0; for(int i=R;i;i-=i&(-i))te[1][++num[1]]=root[i]; for(int i=L-1;i;i-=i&(-i))te[0][++num[0]]=root[i]; return query(k,1,cnt); } void bitupdate(int i,int pos,int v) { for(;i<=cnt;i+=i&(-i))update(root[i],pos,v,1,cnt); }}s;struct node{int op,x,y,z;}q[N];int Hash[N],a[N];char o[5];int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); Hash[cnt++]=a[i]; } for(int i=1;i<=m;i++) { scanf("%s%d%d",o,&q[i].x,&q[i].y); q[i].op=(o[0]=='C'); if(q[i].op==0)scanf("%d",&q[i].z); if(q[i].op==1)Hash[cnt++]=q[i].y; } sort(Hash,Hash+cnt);cnt=unique(Hash,Hash+cnt)-Hash; for(int i=1;i<=n;i++) { a[i]=lower_bound(Hash,Hash+cnt,a[i])-Hash+1; s.bitupdate(i,a[i],1); } for(int i=1;i<=m;i++) { if(q[i].op==0)printf("%d\n",Hash[s.bitquery(q[i].x,q[i].y,q[i].z)-1]); else { q[i].y=lower_bound(Hash,Hash+cnt,q[i].y)-Hash+1; s.bitupdate(q[i].x,a[q[i].x],-1);a[q[i].x]=q[i].y;s.bitupdate(q[i].x,a[q[i].x],1); } } return 0;}/****************************************/