"Bzoj" "1901" "Zju2112" Dynamic rankings

Source: Internet
Author: User

Fill a hole again.

Dynamic maintenance interval K-Large (with single-point modification)

First the naked interval K-Big we are using the "prefix and" thought, to achieve O (n) preprocessing, O (1) Find tree query, then if it is dynamic? We can use the idea of the tree Array (BIT) to make O (logn) changes, O (logn) query (of course, because it is done on the line tree, each need to multiply the complexity of LOGN)

That is, each change, a piece to change Logn tree line, each query is also in Logn tree segment tree down together to find!

  

1 //Bzoj 19012#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <iostream>6#include <algorithm>7 #defineRep (i,n) for (int i=0;i<n;++i)8 #defineF (i,j,n) for (int i=j;i<=n;++i)9 #defineD (i,j,n) for (int i=j;i>=n;--i)Ten #defineLowbit (x) ((x) & (-(x))) One using namespacestd; A Const intn=110086; -  - structtree{ the     intCnt,l,r; -}t[n* -]; - intn,m,num=0,root[n],a[n>>1],b[n],dat[n>>1][4],size=0, cnt=0; - intLc,rc,ln[n],rn[n]; +  - #defineMid (L+r>>1) + voidBuildint&o,intLintR) { Ao=++cnt; T[o].cnt=0; at     if(L==R)return; - build (T[o].l,l,mid); -Build (t[o].r,mid+1, R); - } -  - voidUpdata (int&o,intLintRintPosintval) { int[++cnt]=t[o],o=cnt,t[o].cnt+=Val; -     if(L==R)return; to     if(Pos <=mid) Updata (t[o].l,l,mid,pos,val); +     ElseUpdata (t[o].r,mid+1, r,pos,val); - } the  * voidModifyintXintPosintval) { $      for(X;x<=n;x+=lowbit (x))//Change Logn tree at oncePanax NotoginsengUpdata (Root[x],1, num,pos,val); - } the  + intQueryintIintJintrank) { A     intL=1, r=num; the     intTl=0, tr=0; +      -      while(l!=R) { $Tl=tr=0; $F (I,1, LC) TL+=T[T[LN[I]].L].CNT;//and add up the Logn tree. -F (I,1, RC) tr+=t[t[rn[i]].l].cnt; -         if(tr-tl>=rank) { theF (I,1, LC) LN[I]=T[LN[I]].L;//look left . -F (I,1, RC) rn[i]=T[RN[I]].L;WuyiR=mid; the         } -         Else{ WuF (I,1, LC) LN[I]=T[LN[I]].R;//look right . -F (I,1, RC) rn[i]=T[RN[I]].R; AboutL=mid+1; rank-=tr-tl; $         } -          -     } -     returnl; A } + #undefMid the intGetans (intLintRintk) { -Rc=lc=0; $      for(r;r;r-=Lowbit (R)) thern[++rc]=Root[r]; the      for(l;l;l-=lowbit (l)) theln[++lc]=Root[l]; the     returnQuery1, num,k); - } in  the voidsolve () { theSort (b +1, b+size+1); AboutNum=unique (b +1, b+size+1)-b-1;//This magical usage ... What is the meaning?  theF (I,1, n) a[i]=lower_bound (b +1, b+num+1, A[i])-b; theBuild (root[0],1, num); theF (I,1, n) modify (I,a[i],1); +F (I,1, M) { -         if(dat[i][0]==0) printf ("%d\n", b[Getans (dat[i][1]-1, dat[i][2],dat[i][3]) ]); the         Else{Bayi             intPos=lower_bound (b +1, b+num+1, dat[i][2])-b; theModify (dat[i][1],a[dat[i][1]],-1); thea[dat[i][1]]=Pos; -Modify (dat[i][1],a[dat[i][1]],1); -         } the     } the } the  the intMain () { - #ifndef Online_judge theFreopen ("file.in","R", stdin); the     #endif the     intt=1;94 //scanf ("%d", &t); the      while(t--){ thesize=cnt=num=0; thememset (b,0,sizeofb);98memset (T,0,sizeoft); Aboutmemset (DAT,0,sizeofdat); -scanf"%d%d",&n,&m);101F (I,1, N) {102scanf"%d",&a[i]);103b[++size]=A[i];104         } the         Charcmd[3];106F (I,1, M) {107scanf"%s", cmd);108             if(cmd[0]=='C'){109dat[i][0]=1; thescanf"%d%d", &dat[i][1],&dat[i][2]);111b[++size]=dat[i][2]; the             }113             Else{ thedat[i][0]=0; thescanf"%d%d%d", &dat[i][1],&dat[i][2],&dat[i][3]); the             }117         }118 solve ();119     } -     return 0;121 }122 /************************************************** 123 using the idea of bit to realize the conversion of prefix-difference logn124 the bare, persistent segment tree is the one that maintains an interval [1,i] (prefix and) per tree the query O (1), and the modification requires O (n)126 dynamically Modify & Query-->bit A durable segment tree127 Each node of the bit represents an interval of the original array - and then use the persistence line tree to maintain the interval.129 log (n) a line tree along the search the **************************************************/ 
View Code

"Bzoj" "1901" "Zju2112" Dynamic rankings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.