splay模板基本操作

2021-08-04 22:14:35 字數 1092 閱讀 7898

splay模板指標實現

splay中序遍歷維護原序列下標的順序,翻轉後這個順序會改變,但是splay中第x個數代表變換後序列中第x個數

這樣就可以直接查詢變換後的序列

重在**

文藝平衡樹

#include#include#include#include#define inf 0x3f3f3f3f

using namespace std;

struct node

*null=new node(0),*root=null;//空指標可以直接建出來,null容易出錯

node::node(int x)

void node ::pushdown()

}void node :: pushup()

struct splay

void zig(node *x)//右旋

void zag(node *x)//左旋

void splay(node *x,node *tar)//把x旋到tar的子節點

if(x==y->ls)

else

}x->pushup();

}node* findx(node *x,int y)//查詢第y個數,y不是權值,是序列中的順序

}return x;

}void find(int x,int y)//找到要操作的區間

void insert(node *&x,int y,node *z)//插入乙個權值為y的數

x->pushdown();

insert(x->rs,y,x);

}}sp;

int n,m,x,y;

int main()

for(int i=2;i<=n+1;i++)

printf("%d ",sp.findx(root,i)->num);

// while(1);

return 0;

}

Splay基本操作

splay基本操作 using namespace std struct splayt maxn int newp void rotate int x void splay s int x,int destnation rotate x 無論共不共線都要旋x if destnation 0 root...

splay模板複習

splay模板 記得加哨兵!include using namespace std pre def const double pi acos 1.0 const int inf 0x3f3f3f3f typedef long long ll typedef unsigned long long ul...

待補 splay 模板

define crt secure no warnings include include include include include include using namespace std define rep i,t,n for int i t i n i define per i,n,t ...