學習筆記 普通平衡樹Splay

2022-04-29 23:54:11 字數 932 閱讀 5612

哈哈哈哈哈哈哈終於會打\(splay\)啦

現在我來發一下\(splay\)的講解吧

小蒟蒻由於碼風與他人不同,所以自己找了上百篇碼風詭異的\(splay\)合成的,感謝\(zcysky\)的**與我碼風相近,讓我看懂了

首先,\(splay\)其實就是把一棵二叉搜尋樹變成一棵深度不會超過\(logn\)的二叉搜尋樹,它在不斷旋轉至深度至\(logn\)

當然,那麼就少不了\(rotate\)和\(splay\)操作

具體看**好了,說的比較麻煩

#include using namespace std;

const int maxn=100000+10;

int ch[maxn][2],fa[maxn],siz[maxn],cnt[maxn],key[maxn];

int sz,rt;

inline void clear(int x)

inline bool get(int x)

inline void update(int x)

}inline void rotate(int x)

inline void splay(int x)

inline void insert(int val)

int x=rt,y=0;

while(1)

y=x;x=ch[x][key[x]1)

if(!ch[rt][0]&&!ch[rt][1])

if(!ch[rt][0])

else if(!ch[rt][1])

splay(pre());

ch[rt][1]=ch[x][1];

fa[ch[x][1]]=rt;

clear(x);update(rt);

}int main()

}return 0;

}

splay 普通平衡樹

平衡樹是一種很玄學的操作,這裡提供兩種基本模板 指標模板 這裡寫 片 include include include include include include using namespace std const int inf 1e9 const int max q 1e5 10 int n,...

Splay 普通平衡樹模板

口訣 rotate 先上再下,最後自己 splay 祖父未到旋兩次,三點一線旋父親,三點折線旋自己。delete 沒有兒子就刪光。單個兒子刪自己。兩個兒子找前驅。易錯點 rotate 祖父不在自己做根 delete 自己做根父親為0 kth 先減排名後轉移 by dennyqi 2018 inclu...

BZOJ3224 普通平衡樹 splay

題目在這裡 題意 讓你實現一棵樹,實現 插入,刪除,查詢x數的排名,查詢排名為x的數 求x的前驅 前驅定義為小於x,且最大的數 求x的後繼 後繼定義為大於x,且最小的數 這道題最開始我用treap過了,今天打了乙個splay題解。treap題解 include include include usi...