mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:31:59 +00:00
P3369 【模板】普通平衡树
R69586144
This commit is contained in:
parent
9680921911
commit
886c3ea0db
@ -25,11 +25,9 @@ class Treap {
|
||||
std::pair<node *, node *> split(node *, int);
|
||||
std::pair<node *, node *> splitByValue(node *, int);
|
||||
node *merge(node *, node *);
|
||||
int _getRank(node *, int);
|
||||
|
||||
public:
|
||||
Treap();
|
||||
~Treap();
|
||||
|
||||
void insert(int);
|
||||
void erase(int);
|
||||
@ -60,10 +58,6 @@ inline void Treap::node::pushup() {
|
||||
Treap::Treap()
|
||||
: root(nullptr) {}
|
||||
|
||||
Treap::~Treap() {
|
||||
delete root;
|
||||
}
|
||||
|
||||
inline int Treap::getNodeSize(Treap::node *node) {
|
||||
return node == nullptr ? 0 : node->size;
|
||||
}
|
||||
@ -138,14 +132,11 @@ void Treap::erase(int val) {
|
||||
this->root = this->merge(o.first, t.second);
|
||||
}
|
||||
|
||||
int Treap::_getRank(Treap::node *p, int val) {
|
||||
if (p == nullptr) return 1;
|
||||
if (val <= p->val) return this->_getRank(p->left, val);
|
||||
return this->getNodeSize(p->left) + 1 + this->_getRank(p->right, val);
|
||||
}
|
||||
|
||||
inline int Treap::getRank(int val) {
|
||||
return this->_getRank(this->root, val);
|
||||
int Treap::getRank(int val) {
|
||||
auto x = this->splitByValue(this->root, val);
|
||||
int r = this->getNodeSize(x.first) + 1;
|
||||
this->root = merge(x.first, x.second);
|
||||
return r;
|
||||
}
|
||||
|
||||
int Treap::getKth(int k) {
|
||||
|
Loading…
Reference in New Issue
Block a user