From 02391450c0482c2c74822e39117ad0f42e2e6397 Mon Sep 17 00:00:00 2001 From: Baoshuo Ren Date: Thu, 17 Feb 2022 16:19:39 +0800 Subject: [PATCH] =?UTF-8?q?P3369=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E5=B9=B3=E8=A1=A1=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R69538002 --- Luogu/P3369/P3369.cpp | 50 +++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/Luogu/P3369/P3369.cpp b/Luogu/P3369/P3369.cpp index 6392c10a..4afae8f4 100644 --- a/Luogu/P3369/P3369.cpp +++ b/Luogu/P3369/P3369.cpp @@ -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; }