"Problem Analysis"
I heard it was a tree set. Fog
Rage Writes the tree-like array of the Chairman tree, and then Rank1. 23333
Single point modification, interval query +k large number query = Tree array set of Chairman tree.
Code
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <set># Include <map> #include <string> #include <algorithm> #include <vector> #include <iostream > #include <queue>using namespace std; #define MAXN 50005#define Mlog int read () {int x=0,f=1; char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') f=-1; Ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} int N,m;int Rt[maxn<<1],a[maxn],b[maxn<<1],cnt=0,tot=0,sum,rnk,tmp;int ls[maxn<<6],rs[maxn< <6],siz[maxn<<6];int L[MAXN],R[MAXN],OPT[MAXN],X[MAXN],Y[MAXN],Z[MAXN]; void ins (int o1,int & o2,int l,int r,int x,int f) {//printf ("Ins%d%d%d%d%d%d\n", o1,o2,l,r,x,f); O2=++tot; Siz[o2]=siz[o1]+f; if (l==r) return; int mid= (L+R)/2; if (x<=mid) rs[o2]=rs[o1],ins (ls[o1],ls[o2],l,mid,x,f); else Ls[o2]=ls[o1],ins (Rs[o1],rs[o2],mid+1,r,X,F); return;} void Ready (int l,int R) {//cout<< ' ready for ' <<l<< ' <<r<<endl; l--; l[0]=r[0]=0; for (int j=l;j;j-=j& (-J)) l[++l[0]]=rt[j]; for (int j=r;j;j-=j& (-J)) r[++r[0]]=rt[j];//cout<< "L"; for (int j=1;j<=l[0];++j) cout<<l[j]<< ""; cout<<endl;//cout<< "R"; for (int j=1;j<=r[0];++j) cout<<r[j]<< ""; cout<<endl;//cout<< "L"; for (int j=1;j<=l[0];++j) cout<<siz[l[j]]<< ""; cout<<endl;//cout<< "R"; for (int j=1;j<=r[0];++j) cout<<siz[r[j]]<< ""; Cout<<endl;} void Cholef () {//cout<< "Choose Left" <<endl; for (int i=1;i<=l[0];++i) l[i]=ls[l[i]]; for (int i=1;i<=r[0];++i) r[i]=ls[r[i];} void Chorig () {//cout<< "Choose Right" <<endl; for (int i=1;i<=l[0];++i) l[i]=rs[l[i]]; for (int i=1;i<=r[0];++i) r[i]=rs[r[i];} int taksum () {int ret=0; for (int i=1;i<=l[0];++i) ret-=siz[ls[l[i]]; for (int i=1;i<=r[0];++i) ret+=siz[ls[r[i]]; return ret;} int qrnk (int l,int r,int x) {//printf ("Qrnk%d%d%d\n", l,r,x); if (l==r) return 1; int mid= (L+R)/2,tmp=taksum ();//cout<< "Take sum" <<tmp<<endl; if (X<=mid) return Cholef (), Qrnk (l,mid,x); else return Chorig (), Tmp+qrnk (mid+1,r,x);} int qnum (int l,int r,int x) {if (l==r) return l; int mid= (L+R)/2,tmp=taksum (); if (x<=tmp) return Cholef (), Qnum (l,mid,x); else return Chorig (), Qnum (mid+1,r,x-tmp);} int main () {n=read (); M=read (); for (int i=1;i<=n;++i) scanf ("%d", &a[i]), b[++cnt]=a[i]; for (int i=1;i<=m;++i) {scanf ("%d%d%d", &opt[i],&x[i],&y[i]); if (opt[i]!=3) scanf ("%d", &z[i]); if (opt[i]==3) b[++cnt]=y[i]; if (opt[i]==4| | opt[i]==5) B[++cnt]=z[i]; } sort (b+1,b+cnt+1); Cnt=unique (b+1,b+cnt+1)-b-1; for (int i=1;i<=n;++i) A[i]=lower_bound (B+1,b+cnt+1,a[i])-B; for (int i=1;i<=m;++i) {if (opt[i]==1| | opt[i]==4| | opt[i]==5) Z[i]=lower_bound (B+1,b+cnt+1,z[i])-B; if (opt[i]==3) Y[i]=lower_bound (B+1,b+cnt+1,y[i])-B; }//cout<<endl<<endl;//for (int i=1;i<=cnt;++i) cout<<i<< "", cout<<endl;//for (int i =1;i<=cnt;++i) cout<<b[i]<< ""; cout<<endl;//for (int i=1;i<=m;++i) cout<<opt[i]<< "" <<x[i]<< "" <<y[i]< < "" <<z[i]<<endl;//cout<<endl<<endl; for (int i=1;i<=n;++i) for (int j=i;j<=n;j+=j& (-J)) ins (rt[j],rt[j],1,cnt,a[i],1); for (int. i=1;i<=m;++i) {switch (Opt[i]) {case 1:ready (x[i],y[i]); printf ("%d\n", Qrnk (1,cnt,z[i])); Break Case 3:for (int j=x[i];j<=n;j+=j& (-J)) {ins (rt[j],rt[j],1,cnt,a[ X[I]],-1); INS (Rt[j],rt[j],1,cnt,y[i], 1); } A[x[i]]=y[i]; Break Case 2:ready (X[i],y[i]); printf ("%d\n", B[qnum (1,cnt,z[i])); Break Case 4:ready (X[i],y[i]); RNK=QRNK (1,cnt,z[i]);//printf ("Rnk is%d\n", RNK); Ready (X[i],y[i]); printf ("%d\n", B[qnum (1,cnt,rnk-1)]); Break Case 5:ready (X[i],y[i]); Tmp=0; TMP-=QRNK (1,cnt,z[i]); Ready (X[i],y[i]); TMP+=QRNK (1,cnt,z[i]+1);//printf ("It s has%d\n", TMP); Ready (X[i],y[i]); RNK=QRNK (1,cnt,z[i]); Ready (X[i],y[i]); printf ("%d\n", B[qnum (1,cnt,rnk+tmp)]); } }}
Bzoj 3196 tyvj 17,302 forced balance tree-tree array Set Chairman tree