序列終結者 Splay

2022-05-09 18:13:43 字數 1095 閱讀 4080

1.注意在 split 

和 merge

時要特判一下邊界, 否則就會出現邊界錯誤的情況。

2.隨時都要維護父指標。

3.在更新 maxv

和翻轉標記時要判一下左右兒子是否都存在。

#include#include#includeusing namespace std;

const int maxn = 100000 + 3;

int f[maxn], ch[maxn][2], n,m,numv[maxn], maxv[maxn], siz[maxn], tag[maxn], root, cnt , lazy[maxn];

struct operation

inline void pushdown(int x)

if(lazy[x])

}inline void pushup(int x)

inline void rotate(int x)

inline void splay(int x,int &tar)

inline int findx(int x, int top)

return 0;

}inline void split(int &a,int nums,int &b)

if(nums == siz[a])

int u = findx(nums, a);

splay(u, a);

b = ch[a][1];

f[ch[a][1]] = 0, ch[a][1] = 0,

pushup(a);

}inline void merge(int &a,int b)

splay(findx(siz[a], a), a);

ch[a][1] = b, f[b] = a;

pushup(a);

}void build(int l,int r,int &o,int fa)

}t;int main()

if(ops == 2)

if(ops == 3)

t.merge(root, a);

t.merge(root, b);

}return 0;

}

序列終結者 Splay

1.注意在 split 和 merge 時要特判一下邊界,否則就會出現邊界錯誤的情況。2.隨時都要維護父指標。3.在更新 maxv 和翻轉標記時要判一下左右兒子是否都存在。include include includeusing namespace std const int maxn 100000...

序列終結者

時間限制 1 sec 記憶體限制 128 mb 題目描述 給定乙個長度為n的序列,每個序列的元素是乙個整數。要支援以下三種操作 1.將 l,r 這個區間內的所有數加上v。2.將 l,r 這個區間翻轉,比如1 2 3 4變成4 3 2 1。3.求 l,r 這個區間中的最大值。最開始所有元素都是0。輸入...

BZOJ 1251 序列終結者 Splay

題目大意 維護區間的最大值,要求可以區間翻轉和區間加減。思路 弱化版的1500,好長時間沒寫帶標記的splay了,錯誤重重。這個題可以當作帶標記的splay模板了。code include include include include define inf 0x3f3f3f3f define wo...