1901:zju2112 Dynamic Rankings time limit:10 Sec Memory limit:128 MB Description given a sequence of n numbers a[1],a[2],a[3]......a[n], the program must answer the question: What is the small number of K in A[i],a[i+1],a[i+2]......a[j] for a given i,j,k (1≤k≤j-i+ 1), and you can change the value of some a[i], after the change, the program can also continue to answer the above question for the changed a. The first line of input has two positive integers n (1≤n≤10000), M (1≤m≤10000). Indicates the length of the sequence and the number of instructions, respectively. The second line has n number, which means a[1],a[2]......a[n], these numbers are smaller than 10^9. The next M-line describes the format of each line for each instruction in one of the following two formats. Q I j K or C i t Q i j K (I,j,k is a number, 1≤i≤j≤n, 1≤k≤j-i+1) indicates an inquiry instruction asking for a small number of k in the A[i],a[i+1]......a[j]. C i T (1≤i≤n,0≤t≤10^9) means to change a[i] into Tm,n≤10000output
For each query, you need to output his answer, with each output occupying a separate line.
Sample Input5 3
3 2 1) 4 7
Q 1 4 3
C 2 6
Q 2 5 3
Sample Output3
6
HINT If the query is large, we can directly use the Chairman tree, but with the modification operation, we need to add a one-dimensional tree array maintenance so that in each lowbit modification can maintain all the information, query the same. Time complexity O (nlog2n)
#include <map>#include<cmath>#include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#defineINF 1000000007#definell Long Long#defineM 10000010#defineN 10010inlineintRd () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intN,m,v[n],a[n],b[n],k[n];inths[n<<1],ji[n<<1],tt,tot=1;intrt[n],sz[m],ls[m],rs[m],cnt;Chars[Ten];BOOLQ[n];intHshintx) { intL=1, r=Tot,mid,mz; while(l<=r) {Mid=l+r>>1; if(hs[mid]<x) l=mid+1; Elser=mid-1+m]=mid; } returnmz;}voidAddintLstintLintRint&p,intXintW) {P=++CNT; SZ[P]=sz[lst]+W; LS[P]=ls[lst];rs[p]=Rs[lst]; if(L==R)return; intMid=l+r>>1; if(x<=mid) Add (LS[LST],L,MID,LS[P],X,W); ElseAdd (rs[lst],mid+1, r,rs[p],x,w);}inta,b,l[ -],r[ -];intFdintLintRintk) { if(L==R)returnl; intMid=l+r>>1, sl=0, sr=0; for(intI=1; i<=a;i++) sl+=Sz[ls[l[i]]; for(intI=1; i<=b;i++) sr+=Sz[ls[r[i]]; if(sr-sl>=k) { for(intI=1; i<=a;i++) l[i]=Ls[l[i]]; for(intI=1; i<=b;i++) r[i]=Ls[r[i]]; returnFD (L,MID,K); } Else { for(intI=1; i<=a;i++) l[i]=Rs[l[i]]; for(intI=1; i<=b;i++) r[i]=Rs[r[i]]; returnFD (mid+1, r,k-sr+SL); }}intMain () {TT=n=rd (); m=Rd (); for(intI=1; i<=n;i++) ji[i]=v[i]=Rd (); for(intI=1; i<=m;i++) {scanf ("%s", s); A[i]=rd (); b[i]=Rd (); if(s[0]=='Q') k[i]=Rd (); Elseji[++tt]=b[i],q[i]=1; } sort (Ji+1, ji+tt+1); hs[1]=ji[1]; for(intI=2; i<=tt;i++) if(ji[i]!=ji[i-1]) hs[++tot]=Ji[i]; for(intI=1, tp;i<=n;i++) {TP=HSH (V[i]); for(intj=i;j<=n;j+=j& (-j) Add (Rt[j],1, TOT,RT[J],TP,1); } for(intI=1, tp;i<=m;i++) { if(Q[i]) {TP=HSH (V[a[i]); for(intj=a[i];j<=n;j+=j& (-j) Add (Rt[j],1, tot,rt[j],tp,-1); TP=HSH (B[i]); for(intj=a[i];j<=n;j+=j& (-j) Add (Rt[j],1, TOT,RT[J],TP,1); V[a[i]]=B[i]; } Else{a=b=0; for(intj=a[i]-1;j;j-=j& (-j)) l[++a]=Rt[j]; for(intj=b[i];j;j-=j& (-j)) r[++b]=Rt[j]; printf ("%d\n", HS[FD (1, Tot,k[i])); } } return 0;}
Bzoj 1901:zju2112 Dynamic Rankings--Chairman tree, tree-shaped array, hash