You need to write a data structure (which can refer to the title of the topic) to maintain an ordered series, which requires the following actions: Flipping an interval, such as the original ordered sequence is 5 4 3 2 1, the flip interval is [2,4], the result is 5 2 3 4 1
Input
The first behavior n,m n means the initial sequence has n number, this sequence is (1,2......n-1,n) m for the number of rollover operations
Next m line two numbers per line [L,r] Data guarantee 1<=l<=r<=n
Output
Outputs a row of n numbers, indicating the result of the original sequence after M-transform
Sample Input5 3
1 3
1 3
1 4
Sample Output4 3 2) 1 5
HINT
n,m<=100000
Exercises
Given a sequence request interval rollover, you can use splay to maintain, as long as the left interval of the precursor to the root, the right of the subsequent selection to the root of the right child, then the right child of the root of the child's Left child tree is the need to flip the interval, marked maintenance on the line. In fact, it can be found that this is not a strict balance tree, because for the X-node, its left child's weight may not be smaller than the right child. Finally, just follow the middle sequence to output a bit.
1 /**************************************************************2 problem:32233 User: __abcdef__4 language:c++5 result:accepted6 time:3124 Ms7 memory:4020 KB8 ****************************************************************/9 Ten#include <iostream> One#include <cstdio> A#include <cstdlib> -#include <cstring> -#include <cmath> the#include <algorithm> -#include <queue> -#include <vector> -#include <ctime> + using namespacestd; -typedefLong LongLL; + Const intinf=1e9; A Const intmaxn=100005; at intN,m,tot,root; - intKEY[MAXN],LC[MAXN],RC[MAXN],FA[MAXN],SIZ[MAXN]; - intREV[MAXN]; - intans[maxn],cnt; -InlinevoidUpdateintx) { -siz[x]=siz[lc[x]]+siz[rc[x]]+1; in } -InlinevoidPushdown (intx) { to if(Rev[x]) { + swap (lc[x],rc[x]); -rev[lc[x]]^=1; rev[rc[x]]^=1; therev[x]=0; * } $ }Panax NotoginsengInlinevoidR_rotate (intx) { - inty=Fa[x]; thelc[y]=Rc[x]; + if(Rc[x]) fa[rc[x]]=y; Afa[x]=Fa[y]; the if(Y==lc[fa[y]]) lc[fa[y]]=x; + Elserc[fa[y]]=x; -Fa[y]=x; rc[x]=y; $ update (y); update (x); $ } -InlinevoidL_rotate (intx) { - inty=Fa[x]; therc[y]=Lc[x]; - if(Lc[x]) fa[lc[x]]=y;Wuyifa[x]=Fa[y]; the if(Y==lc[fa[y]]) lc[fa[y]]=x; - Elserc[fa[y]]=x; WuFa[y]=x; lc[x]=y; - update (y); update (x); About } $InlinevoidSplay (intXints) { - intp; - while(fa[x]!=s) { - intp=Fa[x]; A if(fa[p]==s) { + if(x==lc[p]) r_rotate (x); the Elsel_rotate (x); - Break; $ } the Else if(x==Lc[p]) { the if(p==Lc[fa[p]]) r_rotate (x), r_rotate (x); the Elser_rotate (x), l_rotate (x); the } - Else if(x==Rc[p]) { in if(p==Rc[fa[p]]) l_rotate (x), l_rotate (x); the Elsel_rotate (x), r_rotate (x); the } About } the if(s==0) root=x; the } theInlinevoidInsertintv) { + if(root==0){ -root=++tot; therc[0]=tot; Key[root]=v; siz[root]=1;Bayi return ; the } the intp,x=Root; - while(x!=0){ -p=x; the if(V<=key[x]) siz[x]++,x=Lc[x]; the Elsesiz[x]++,x=Rc[x]; the } the if(v<=Key[p]) { -lc[p]=++tot; theKey[tot]=v; Fa[tot]=p; siz[tot]=1; the } the Else{94rc[p]=++tot; theKey[tot]=v; Fa[tot]=p; siz[tot]=1; the } theSplay (Tot,0);98 } AboutInlineintFindkth (intXintk) { - pushdown (x);101 if(siz[lc[x]]+1==K)returnx;102 Else if(siz[lc[x]]+1>K)returnfindkth (lc[x],k);103 Else returnFindkth (rc[x],k-siz[lc[x]]-1);104 } theInlinevoidRever (intLintR) {106 intX=findkth (root,l), y=findkth (root,r+2);107Splay (x,0); 108 splay (y,x);109rev[lc[rc[root]]]^=1; the }111InlinevoidPrintintx) { the pushdown (x);113 if(lc[x]!=0) print (lc[x]); theans[++cnt]=Key[x]; the if(rc[x]!=0) print (rc[x]); the }117 intMain () {118scanf"%d%d",&n,&M);119Insert (-inf); Insert (INF); - for(intI=1; i<=n;i++) Insert (i);121 while(m--){122 intL,r;123scanf"%d%d",&l,&R);124 Rever (l,r); the }126 print (root);127 for(intI=2; i<=cnt-1; i++) printf ("%d", Ans[i]); - return 0;129}
Bzoj 3223:tyvj 1729 Literary Balance Tree