版本比较
FHQ-Treap(非旋 Treap)学习笔记
正文
增加 4 行删除 4 行
25 行未改动2627282930303132333412 行未改动4748495051515253545511 行未改动67686970717172737475127 行未改动全部展开20320420520620720720820921021165 行未改动25 行未改动```cpppii split(int x, int key) { if(!x) { return {0, 0}; } } if(tr[x].val < key) { pii t = split(tr[x].rs, key); tr[x].rs = t.fir, update(x); // update 用于更新结点子树大小。 return {x, t.sec};12 行未改动```cppint merge(int x, int y) { if(!x || !y) { return x + y; } } if(tr[x].wei < tr[y].wei) { tr[x].rs = merge(tr[x].rs, y), update(x); return x; } else {11 行未改动void insert(int x) { ++ idx; tr[idx].siz = 1, tr[idx].val = x, tr[idx].wei = getRand(); // getRand() 用于得到一个随机数。 pii t = split(root, x); /* return */ root = merge(merge(t.fir, idx), t.sec); /* return */ root = merge(merge(t.fir, idx), t.sec);}```
## 2.4 删除(erase)127 行未改动全部展开 } int getRand() { return seed *= S; }
public: void insert(int x) { idx ++; tr[idx].val = x, tr[idx].siz = 1, tr[idx].wei = getRand();65 行未改动