0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P3369 【模板】普通平衡树

R69538002
This commit is contained in:
Baoshuo Ren 2022-02-17 16:19:39 +08:00
parent 97ba4f11fc
commit 02391450c0
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -13,21 +13,12 @@ class Treap {
node *left, *right;
int size, val, key;
node()
: left(nullptr), right(nullptr), size(1), val(0), key(rand()) {}
node(int _val)
: left(nullptr), right(nullptr), size(1), val(_val), key(rand()) {}
node();
node(int);
~node();
~node() {
delete left, right;
}
inline void pushup() {
this->size = 1;
if (this->left != nullptr) this->size += this->left->size;
if (this->right != nullptr) this->size += this->right->size;
}
} *root = nullptr;
void pushup();
} * root;
int getNodeSize(node *);
node *find(node *, int);
@ -37,8 +28,8 @@ class Treap {
int _getRank(node *, int);
public:
Treap()
: root(nullptr) {}
Treap();
~Treap();
void insert(int);
void erase(int);
@ -46,6 +37,33 @@ class Treap {
int getKth(int);
} tree;
// struct Treap::node
Treap::node::node()
: left(nullptr), right(nullptr), size(1), val(0), key(rand()) {}
Treap::node::node(int _val)
: left(nullptr), right(nullptr), size(1), val(_val), key(rand()) {}
Treap::node::~node() {
delete this->left, this->right;
}
inline void Treap::node::pushup() {
this->size = 1;
if (this->left != nullptr) this->size += this->left->size;
if (this->right != nullptr) this->size += this->right->size;
}
// class Treap
Treap::Treap()
: root(nullptr) {}
Treap::~Treap() {
delete root;
}
inline int Treap::getNodeSize(Treap::node *node) {
return node == nullptr ? 0 : node->size;
}