總結 伸展樹Splay

2022-05-11 17:16:39 字數 1020 閱讀 3781

感覺我在聯賽還差4天的時候學習splay有點慌,但還是要學一下。

我們先對splay的陣列進行一些定義:

struct nodet[n<<2];
我們的splay應該要支援以下幾個操作:

**如下:

#includeusing namespace std;

const int n=500010;

int root,tot;

inline int gi()

while(ch>='0' && ch<='9')

return f*sum;

}class splaytreet[n<<2];

inline void pushup(int x)

inline void rotate(int x)

public:

inline void splay(int x,int goal)

if(!goal)root=x;

} inline void find(int x)

inline void insert(int x)

if(u)t[u].cnt++;

else

splay(u,0);

} inline int next(int x,int f)

else t[nxt].ch[0]=0;

} inline int kth(int x)

} }inline int val(int u)

inline int ch0size()

}splay;

int main()

if(opt==4)printf("%d\n",splay.kth(x+1));

if(opt==5)printf("%d\n",splay.val(splay.next(x,0)));

if(opt==6)printf("%d\n",splay.val(splay.next(x,1)));

} return 0;

}

伸展樹splay學習小記

splay是基本操作,rotate是splay的基本操作。splay now,root 把now splay到root的下面。單旋和雙旋就不說了。我們可以簡化操作,如果是一字型 方向相同 則先旋father,否則先旋now。然後再旋now。rotate now是指將now繞father rotate...

資料結構 Splay伸展樹 普通平衡樹

題目描述 您需要寫一種資料結構 可參考題目標題 來維護一些數,其中需要提供以下操作 插入x數 刪除x數 若有多個相同的數,因只刪除乙個 查詢x數的排名 若有多個相同的數,因輸出最小的排名 查詢排名為x的數 求x的前驅 前驅定義為小於x,且最大的數 求x的後繼 後繼定義為大於x,且最小的數 輸入 第一...

學習筆記第六節 伸展樹splay

正文 說到伸展樹,大家想到的可能是複雜,冗長,很容易打錯,思路卻很好理解。沒錯,伸展樹的確是這麼乙個東西,如果你做多了題,學會用它之後,你就會覺得很得心應手,輕鬆面對許多高階資料結構題。這個當然也是乙個鍛鍊人的耐心的東西,有乙份 調了4天emm。伸展樹是一棵二叉搜尋樹,就是說,它是一棵單一關鍵字排序...