[bzoj1552] [cerc2007]robotic sort&&[bzoj3506][cqoi2014] Sorting picker

Source: Internet
Author: User

The very garbage of a balanced tree, the result was a day. It's hard to be whining.

First of all, I have to say that the online puzzle so that I am not familiar with the balance tree of color pens is very difficult to understand-not good.

Fortunately Sinogi big guy very God, cut off at a glance, and with a more wonderful solution.

Test instructions in the operation, is the first time the number of the i-1 and numbered I referred to the Genheggen of the right son, the root of the right son of the Zuozi to play flip mark.

The number of numbers in the balance tree is recorded with an outer array of the largest of the original height. It can be operated directly.

Note that there is the same height, when discretization is done directly by the height of the first keyword, the second keyword is numbered.

And every time splay to the root to the current node are pushdown again. And the first pushdown to continue operation! Including judging there's no son left!

Maybe I'm the only idiot.

#include <bits/stdc++.h>using namespacestd;Const intn=200010; inlineintRead () {intR=0, c=GetChar ();  while(!isdigit (c)) c=GetChar ();  while(IsDigit (c)) R=r*Ten+c-'0', c=GetChar (); returnR;}#defineLS Ch[x][0]#defineRS Ch[x][1]intch[n][2],siz[n],fa[n],rev[n],pos[n];intRt,tot;structqwq{intV,p;} A[n];BOOLCMPV (qwq p,qwq q) {if(P.V==Q.V)returnp.p<Q.P; returnp.v<q.v;}BOOLcmpp (qwq p,qwq q) {returnp.p<Q.P;}voidppintx) {Siz[x]=siz[ls]+siz[rs]+1;}voidPdintx) {    if(Rev[x]) {rev[x]=0;        Swap (LS,RS); REV[LS]^=1; rev[rs]^=1; }}int Get(intx) {    returnx==ch[fa[x]][1];}voidRotateintx) {    inty=fa[x],z=fa[y],px=Get(x), py=Get(y); intt=ch[x][px^1]; CH[X][PX^1]=y;fa[y]=x; CH[Y][PX]=t;fa[t]=y; if(z) ch[z][py]=x;fa[x]=Z; PP (y);}intS[n];voidSplay (intXintLim) {    inttop=0;  for(intI=x;i;i=fa[i]) s[++top]=i;  for(inti=top;i;i--) PD (S[i]); inty=Fa[x];  while(y^Lim) {        if(fa[y]^Lim) Rotate (Get(x) = =Get(y)?y:x); Rotate (x); y=Fa[x]; } RT=!lim?x:rt;pp (x);}intNXT () {PD (RT);intx=ch[rt][1];  while(PD (x), ch[x][0]) x=ch[x][0]; returnx;}intBuildintLintR) {    if(L>r)return 0; intMid=l+r>>1, x=++tot; LS=build (l,mid-1); fa[ls]=x; RS=build (mid+1, r); fa[rs]=x; POS[A[MID].V]=x; PP (x);returnx;}intMain () {intn=read (); a[1].v=0, a[n+2].v=n+1;  for(intI=2; i<=n+1; i++) A[I].V=read (), a[i].p=i; Sort (a+2, a+n+2, CMPV);  for(intI=2; i<=n+1; i++) A[I].V=i-1; Sort (a+2, a+n+2, CMPP); RT=build (1, n+2);  for(intI=1; i<=n;i++){        intX=pos[i];splay (x,0); printf ("%d", Siz[ls]);if(i^n) printf (" "); X=NXT (); inty=pos[i-1]; Splay (Y,0); splay (X,RT); REV[LS]^=1; }}

[bzoj1552] [cerc2007]robotic sort&&[bzoj3506][cqoi2014] Sorting picker

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.