43 std::array<int, maxNode>
key = {};
49 std::array<int, maxNode>
cnt =
51 std::array<int, maxNode>
size = {};
161 }
else if (k <
key[x]) {
173 int x =
root, pre = -1;
189 int x =
root, next = -1;
249 std::cout <<
"All tests have successfully passed!\n";
const int maxNode
maximum number of nodes
Struct representation of the treap.
int treapCnt
Total number of current nodes in the treap.
int root
root of the treap
std::array< int, maxNode > key
Node identifier.
void insert(int k)
Insert element (External method)
void _insert(int &x, int k)
Insert a value into the specified subtree (internal method)
void rotate(int &x, int t)
Rotate without breaking the property of BST.
int get_next(int k)
Get the successor node of element k.
std::array< int, maxNode > priority
Random priority.
int _get_rank(int x, int k)
Query the rank of specified element (internal method)
void erase(int k)
Erase element (External method)
void update(int x)
Update the subtree size of the node.
int get_k_th(int k)
Get the KTH largest value (External method)
int get_predecessor(int k)
Get the predecessor node of element k.
std::array< std::array< int, 2 >, maxNode > childs
int get_rank(int k)
Get the rank of specified element (External method)
int _get_k_th(int &x, int k)
Find the KTH largest value (internal method)
void _erase(int &x, int k)
Erase a value from the specified subtree (internal method)
std::array< int, maxNode > size
The number of copies per node.
std::array< int, maxNode > cnt
Maintains the subtree size for ranking query.
static void test()
Self-test implementations.