0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 01:28:49 +00:00

#99. 【模板】普通平衡树

https://sjzezoj.com/submission/49793
This commit is contained in:
Baoshuo Ren 2022-02-18 14:39:32 +08:00
parent 2b064d1f0d
commit 9680921911
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -23,7 +23,6 @@ class Treap {
std::pair<int, int> splitByValue(int, int);
int merge(int, int);
int find(int, int);
int _getRank(int, int);
public:
void insert(int);
@ -140,14 +139,11 @@ void Treap::erase(int v) {
this->root = this->merge(o.first, t.second);
}
int Treap::_getRank(int p, int v) {
if (!p) return 1;
if (v <= this->tr[p].v) return this->_getRank(this->tr[p].l, v);
return this->tr[this->tr[p].l].s + 1 + this->_getRank(this->tr[p].r, v);
}
inline int Treap::getRank(int v) {
return this->_getRank(root, v);
auto x = this->splitByValue(this->root, v);
int r = this->tr[x.first].s;
this->root = merge(x.first, x.second);
return ++r;
}
int Treap::getKth(int k) {