版本比较
ZR-FHQ-Treap
正文
增加 4 行删除 4 行
37 行未改动38394041424243444546340 行未改动全部展开38738838939039139139239339439591 行未改动487488489490491491492493494495102 行未改动全部展开59859960060160260260360460560621 行未改动37 行未改动 int val; 存储的值 int pri; 随机优先级 int size; 子树大小(用于找排名) Node *l, *r; 左右子节点
Node(int v) : val(v), pri(rand()), size(1), l(nullptr), r(nullptr) {}};```
340 行未改动全部展开 }; node* root = nullptr; //mt19937 rng{random_device{}()}; mt19937 rng{time(0)};//实测还是这个好用 unsigned int random_priority() {//梅森随机化 unsigned int random_priority() {//梅森随机化 return rng(); } void up_si(node *u){// 更新节点大小(包含重复元素) if(u) u->si = (u->l ? u->l->si : 0) + (u->r ? u->r->si : 0) + u->cnt;91 行未改动 case 5: cout << s.get_pre(x) << "\n"; break; case 6: cout << s.get_suc(x) << "\n"; break; } }
return 0;}```
102 行未改动全部展开
1. [模版](https://www.luogu.com.cn/problem/P3369)2. [维护数列](https://www.luogu.com.cn/problem/P2042)3. [SuperMemo](https://vjudge.net/problem/POJ-3580)
下面是可持久化 FHQ-Treap(进阶应用):1. [火星商店问题](https://www.luogu.com.cn/problem/P4585)2. [可持久化线段树 1](https://www.luogu.com.cn/problem/P3919)
21 行未改动