# "bzoj-1552&3506" robotic sort& sort picker splay

Source: Internet
Author: User

1552: [cerc2007]robotic sort time limit:5 Sec Memory limit:64 MB
submit:806 solved:329
[Submit] [Status] [Discuss] Description

Input

Enter a total of two lines, the first behavior of an integer n,n indicates 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

Output a total line, n spaces separated by a positive integer p1,p2,p3 ... The PN,PI represents the position of the article I small before the first I 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

Solution

Splay Basic Operation ...

We first order the given sequence, the first keyword is the number, the second keyword is a timestamp, and then use the splay to maintain the sequential sequence can be

Or you can consider maintaining min and Pos

Splay to write often! It's as slow as * *

Code
`#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;inlineintRead () {intx=0;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') {ch=GetChar ();}  while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx;}#defineMAXN 100010intN,POS[MAXN];structnode{intid,t;} A[maxn];inlineBOOLCMP (Node A,node B) {returnA.id==b.id? a.t<b.t:a.id<b.id;}namespacesplaytree{intsize[maxn],root,sz,fa[maxn],son[maxn];BOOLREV[MAXN]; #defineLS (x) son[x]#defineRS (x) son[x]inlinevoidUpdate (intNow) {size[now]=size[ls-]+size[rs (now)]+1;} InlinevoidPushdown (intNow ) {        if(!rev[now])return; Rev[ls (now)]^=1; Rev[rs (now)]^=1; Swap (LS (now), RS (now)); rev[now]=0; } InlineBOOLRight (intNow) {returnson[fa[now]]==Now ;} InlinevoidRotateintNow ) {pushdown (Fa[now]);        Pushdown (now); intF=fa[now],gf=fa[f],wh=Right (now); SON[F][WH]=son[now][wh^1]; fa[son[f][wh]]=F; FA[F]=now; son[now][wh^1]=f; fa[now]=GF; if(GF) son[gf][son[gf]==f]=Now ; Update (f);    Update (now); } InlinevoidSplay (intNowinttar) {         for(intF (F=fa[now])! =tar; rotate (now))if(Fa[f]!=tar) rotate (now) ==right (f)?F:now); if(!tar) root=Now ; } InlineintGetX (intk) {intx=Root;  while(1) {pushdown (x); if(K<=size[ls (x)]) x=ls (x); Else if(K==size[ls (x)]+1)returnx; ElseK-=size[ls (x)]+1, x=rs (x); }        return-1; } InlineintGETK (intx) {splay (x,0);returnSize[ls (x)];} InlineintBuildtree (intLintRintLast ) {        if(r<l)return 0; intMid= (l+r) >>1, now=++sz; Pos[a[mid].id]=now; fa[now]=Last ; intLson=buildtree (l,mid-1, now), Rson=buildtree (mid+1, R,now); son[now]=lson; son[now]=Rson;        Update (now); returnNow ; } InlinevoidReverse (intLintR) {splay (L,0), splay (r,l); Rev[ls (RS (root))]^=1;} InlinevoidInit () {Root=buildtree (1, n+2,0);}}intMain () {N=read ();  for(intI=2, t=0; i<=n+1; i++) A[i].id=read (), a[i].t=++T; a.id=0; a[n+2].id=n+2; Stable_sort (A+2, a+n+2, CMP);  for(intI=1; i<=n; i++) a[a[i+1].t+1].id=i;//for (int i=1; i<=n+2; i++) printf ("%d", a[i].id); Puts ("");Splaytree::init ();  for(intI=1; i<=n; i++)        {            intLoc=SPLAYTREE::GETK (Pos[i]); intX=splaytree::getx (i), Y=splaytree::getx (loc+2);//printf ("%d%d\n", x, y);splaytree::reverse (x, y); printf ("%d%c", Loc,i!=n?' ':'\ n'); }    return 0;}`

and char brother, Dragon Elder brother, guilt tune splay ... Feel mentally handicapped + +

"bzoj-1552&3506" robotic sort& sort picker splay

Related Keywords:

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.