"Bzoj" "1552" "Cerc2007" robotic sort/"3506" "CQOI2014" sorting picker

Source: Internet
Author: User

Splay

Discretization of +splay maintenance sequences ...

All right, let's talk about some of the wrong points I've encountered in this problem:

1. discretization

2. Since the location of the number found must be greater than or equal to I, so in fact, after it splay to the root, I node can only splay to its left son, not the right son ... and accordingly, the area that represents this should be c[c[root][0]][1] uh ... The right son of the left son of root = = Whole reversed ... Well, don't worry about the details, I don't know why I suddenly have to write [face-covering bears] in reverse.

3. After the modification operation, make sure to splay the modified node immediately! In this problem is when find the minimum node, set it to infinity, be sure to splay a bit ... Otherwise, WA, tat.

1 /**************************************************************2 problem:15523 User:tunix4 language:c++5 result:accepted6 time:2764 Ms7 memory:4888 KB8 ****************************************************************/9  Ten //Bzoj 1552 One#include <cstdio> A#include <cstring> -#include <cstdlib> -#include <iostream> the#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;i--) + using namespacestd; -typedefLong LongLL; +InlineintGetint () { A     intR=1, v=0;CharCh=GetChar (); at      for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') r=-1; -      for(; isdigit (ch); Ch=getchar ()) v=v*Ten+ch-'0'; -     returnr*v; - } - Const intn=1e5+Ten, inf=~0u>>2; - /******************template*********************/ in structnode{intV,pos;} A[n]; - BOOL operator< (node A,node b) {returna.pos<B.pos;} to BOOLCMP (node A,node b) {returna.v<b.v| | (A.V==B.V && a.pos<b.pos);} + intd[i][2],fa[n],v[n],mn[n],size[n],tot,root,n; - BOOLRev[n]; the #defineL C[x][0] * #defineR C[x][1] $ voidPush_down (intx) {Panax Notoginseng     if(Rev[x]) { -rev[l]^=1; rev[r]^=1; theSwap (L,R); rev[x]=0;  +     } A } the voidPUSH_UP (intx) { +mn[x]=V[x]; -     if(L) mn[x]=min (mn[x],mn[l]); $     if(R) mn[x]=min (mn[x],mn[r]); $size[x]=size[l]+size[r]+1; - } - voidRotate (intx) { the     inty=fa[x],z=fa[y],l=c[y][1]==x,r=l^1; -c[z][c[z][1]==y]=x;WuyiFa[x]=z; Fa[y]=x; fa[c[x][r]]=y; theC[Y][L]=C[X][R]; c[x][r]=y; - push_up (y); Wu } - intSt[n]; About voidPreview (intx) { $     inttop=0; st[++top]=x; -      for(intI=x;fa[i];i=Fa[i]) -st[++top]=Fa[i]; -D (I,top,1) Push_down (St[i]); A } + voidSplay (intXints=0){ the     inty; -      for(Preview (x); fa[x]!=s; Rotate (x)) $         if(fa[y=fa[x]]!=s) Rotate (c[y][1]==x^c[fa[y]][1]==y?x:y); the push_up (x); the     if(!s) root=x; the } the voidNew_node (int&x,intFintkey) { -x=++tot; infa[x]=F; thev[x]=mn[x]=key; theRev[x]=l=r=0; Aboutsize[x]=1; the } the voidBuild (int&x,intFintLintR) { the     if(L>r)return; +     intMid=l+r>>1; - New_node (X,F,A[MID].V); theBuild (l,x,l,mid-1);BayiBuild (r,x,mid+1, R); the push_up (x); the } - intKthintXintk) { - Push_down (x); the     if(size[l]+1==K)returnx; the     Else if(size[l]>=k)returnkth (l,k); the     Else returnKTH (r,k-size[l]-1); the } - intFindmin (intx) { the Push_down (x); the     if(L && mn[x]==mn[l])returnfindmin (L); the     Else if(R && Mn[x]==mn[r])returnFindmin (R) +size[l]+1;94     Else{V[x]=inf; PUSH_UP (x);returnsize[l]+1;} the } the intMain () { then=getint ();98v[0]=mn[0]=a[0].v=a[n+1].v=INF; AboutF (I,1, n) {a[i].v=getint (); a[i].pos=i;} -Sort (A +1, a+n+1, CMP);101F (I,1, N) a[i].v=i;102Sort (A +1, a+n+1);103Build (Root,0,0, n+1);104F (I,1, N) { the         intt1=findmin (root);106 splay (KTH (ROOT,T1));107printf"%d", t1-1);if(i!=n) printf (" ");108Splay (KTH (root,t1+1)); Splay (KTH (root,i), root);109         intpos=c[c[root][0]][1]; the         if(POS) rev[pos]^=1;111 splay (POS); the     }113     return 0; the } the 
View Code 1552: [cerc2007]robotic sort time limit:5 Sec Memory limit:64 MB
submit:436 solved:186
[Submit] [Status] [Discuss] Description input input A total of two lines, the first behavior of an integer n,n represents the number of items, 1<=n<=100000. The second behavior n a positive integer separated by a space, representing the number of the first rank of n items. Output outputs a total of one row, n spaces separated by a positive integer p1,p2,p3 ... Pn, (1 < = Pi < = N), pi indicates the position of the item where I was small before the first operation. Note: If a small item of I has been placed in the correct position Pi before the first operation, we will reverse the interval [PI,PI] (single item). Sample Input6
3 4 5 1 6 2

Sample Output4 6 4 5 6 6
Hintsource

HNOI2009 Training Day6

[Submit] [Status] [Discuss]

"Bzoj" "1552" "Cerc2007" robotic sort/"3506" "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.