-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplicit_treap.cpp
More file actions
62 lines (57 loc) · 1.34 KB
/
Copy pathimplicit_treap.cpp
File metadata and controls
62 lines (57 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
class ImplicitTreap {
struct Node {
int size;
int priority;
Node *left, *right;
};
Node* head;
void merge(Node* root, Node*& l, Node*& r) {
if (l == nullptr) {
root = r;
return;
}
if (r == nullptr) {
root = l;
return;
}
if (r->priority > l->priority) {
root = r;
merge(root->left, l, r->left);
} else {
root = l;
merge(root->right, l->right, r);
}
}
void split(Node* root, int key, Node*& l, Node*& r) {
// ImplicitTreap newTree = null;
// int curIndex = SizeOf(Left) + 1;
// if (curIndex <= x)
// {
// if (Right == null)
// R = null;
// else
// Right.Split(x - curIndex, out newTree, out R);
// L = new ImplicitTreap(y, Cost, Left, newTree);
// L.Recalc();
// }
// else
// {
// if (Left == null)
// L = null;
// else
// Left.Split(x, out L, out newTree);
// R = new ImplicitTreap(y, Cost, newTree, Right);
// R.Recalc();
// }
}
int size_of(Node* n) { return n == nullptr ? 0 : n->size; }
int recalc(Node* n) { return size_of(n->left) + size_of(n->right) + 1; }
public:
ImplicitTreap() { head = nullptr; }
}