luogup3391一道模板題
學習了spl
ay
splay
spla
y區間翻轉的姿勢
具體就是先建兩個虛擬節點1,n
+2
1,n+2
1,n+
2,然後按節點下標+1+1
+1將區間樹建出來,這時候排名為k
kk的就是第k
kk個數。
翻轉的時候先把(l+
1)−1
(l+1)-1
(l+1)−
1提到根,再把(r+
1)+1
(r+1)+1
(r+1)+
1提到根的右兒子,然後(r+
1)+1
(r+1)+1
(r+1)+
1的左兒子就是一整個區間了,然後把它打上rev
revre
v標記,fin
dfind
find
查詢排名的時候記得下放一下標記,pus
hdow
npushdown
pushdo
wn的時候只要swa
pswap
swap
一下左右兒子就好啦。
昨天寫的spl
ay
splay
spla
y是直接旋到根的,今天寫了一下旋轉到固定點的qwq
qwqqw
q
#include
#include
#include
#include
#include
#define n 100005
using
namespace std;
int n,m,ch[n][2
],siz[n]
,fa[n]
,root,rev[n]
;inline
intrd()
inline
void
pushup
(int x)
inline
void
pushdown
(int x)
}inline
intget
(int x)
inline
void
rotate
(int x,
int&k)
inline
void
splay
(int x,
int&k)
rotate
(x,k);}
}void
build
(int x,
int l,
int r)
intfind
(int x,
int k)
inline
void
rever
(int l,
int r)
intmain()
for(
int i=
2;i<=n+
1;i++
)printf
("%d "
,find
(root,i)-1
);return0;
}
(模板)Splay 平衡樹
不會講解,直接上板子,按照洛谷p3369的要求 include include include using namespace std const int maxn 1000000 int ch maxn 2 f maxn size maxn cnt maxn key maxn int nodecn...
平衡樹 Splay 模板
又是 機房最後乙個學spl ay splay splay的人 參考d al ao dalao dalao部落格 寫的非常好!最後放上我的 有個地方應該寫ch root 0 ch root 0 ch roo t 0 手殘寫成ch root 1 ch root 1 ch roo t 1 還查不出來t t...
文藝平衡樹(splay模板)
題幹 splay模板,要求維護區間反轉。splay是一種碼量小於treap,但支援排名,前驅後繼等treap可求的東西,也支援區間反轉的平衡樹。但是有兩個壞處 1.splay常數遠遠大於treap以及stl中的set。2.沒有可持久化splay,但有可持久化treap。下面是 1.pushup以及p...