Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Node // min-heap on int64
- {
- Node *left;
- Node *right;
- ll x;
- Node(ll x):
- left(NULL),
- right(NULL),
- x(x)
- {}
- };
- Node* merge(Node *a, Node *b)
- {
- if (a == NULL)
- return b;
- if (b == NULL)
- return a;
- if (a->x > b->x)
- swap(a, b);
- a->right = merge(a->right, b);
- swap(a->right, a->left);
- return a;
- }
- Node* push(Node *root, ll x)
- {
- return merge(root, new Node(x));
- }
- Node* pop(Node *root)
- {
- return merge(root->left, root->right);
- }
- ll min(Node *root)
- {
- return root->x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement