splay第一題,有了treap的基礎以後感覺splay還是比較好理解的,splay的優勢在於程式設計複雜度比較低且效率不錯,通過splay操作以及衍生的split和merge操作可以實現很強大的功能。
1 #include 2 #include 3 #include 4using
namespace
std;56
struct
node 719
20void
maintain()
2128
if ( ch[1] !=null )
2932}33
34void
pushdown()
3543}44
};45
46bool ok( int
val )
4750
51void inorder( node *o )
5259
60void rotate( node * & o, int
d )61
6970
void splay( node * & o, int
k )71
90else
9194
}95 rotate( o, d ^ 1
);96}97
}9899 node * build( int l, int
r )100
112113
void split( node * o, int k, node * & left, node * &right )
114121
122 node * merge( node * left, node *right )
123129
130int
main ()
131146
inorder(root);
147}
148return0;
149 }
uva 11922 (伸展樹模板題)
給你乙個長度為n 的序列 初始值為1到n 有m 次操作,每次操作有l r 你需要將l 到 r 的數字翻轉。然後放到最後 m次操作後輸出答案。includeusing namespace std const int inf 0x3f3f3f3f struct node void maintain vo...
NOI2005 維護數列 splay
請寫乙個程式,要求維護乙個數列,支援以下6種操作 請注意,格式欄中的下劃線 表示實際輸入檔案中的空格 1.插入 insert posi tot c1 c2 ctot 在當前數列的第posi個數字後插入tot個數字 c1,c2,ctot 若在數列首插入,則posi為0 2.刪除 delete posi...
noi2005 維護序列。 splay
挑戰自己寫了一下這道noi歷史上最 的資料結構,noi2005的維護序列,非常 非常 在經過4小時的debug後一次ac了 如果再賽場上以我現在水平一定搞不出來。吃一塹長一智,這題對平衡樹的操作更加深入 由於oj上的記憶體限制只有64mb。所以為了記憶體,加了個 棧。後來又加了個 棧,棧指的是被刪除...