bzoj 3224 平衡樹 splay 模板

2021-09-26 07:20:52 字數 1475 閱讀 9481

bzoj 3224

插入x數

刪除x數(若有多個相同的數,因只刪除乙個)

查詢x數的排名(若有多個相同的數,因輸出最小的排名)

查詢排名為x的數

求x的前驅(前驅定義為小於x,且最大的數)

求x的後繼(後繼定義為大於x,且最小的數)

#include

#include

#include

using namespace std;

#define maxn 1000000

int ch[maxn][2

],f[maxn]

,size[maxn]

,cnt[maxn]

,key[maxn]

;int sz,root;

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 x)

int now=root,fa=0;

while(1

) fa=now;

now=ch[now]

[key[now]

(now==0)

}}inline

intfind

(int x)

ans+

=cnt[now]

; now=ch[now][1

];}}

}inline

intfindx

(int x)}}

inline

intpre()

inline

intnext()

inline

void

del(

int x)if(

!ch[root][0

]&&!ch[root][1

])if(

!ch[root][0

])elseif(

!ch[root][1

])int leftbig=

pre(

),oldroot=root;

splay

(leftbig)

; ch[root][1

]=ch[oldroot][1

];f[ch[oldroot][1

]]=root;

clear

(oldroot)

;update

(root);}

intmain()

}}

bzoj3224普通平衡樹

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

BZOJ3224 普通平衡樹

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

BZOJ3224 普通平衡樹

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