Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void insert(Node* &t, Node* &p) {
- if (t == nullptr) {
- t = p;
- return;
- }
- if (p->prior > t->prior) {
- swap(t, p);
- nodepair q = split(p, t->key);
- t->l = q.fi;
- t->r = q.se;
- upd(t);
- return;
- }
- if (p->key <= t->key) {
- t->val++; t->sum += p->key;
- insert(t->l, p);
- } else {
- t->val++; t->sum += p->key;
- insert(t->r, p);
- }
- }
- void remove(Node* &t, int x) {
- if (t->key == x) {
- t = merge(t->l, t->r);
- if (t) upd(t);
- return;
- }
- if (x < t->key) {
- t->val--; t->sum -= x;
- remove(t->l, x);
- } else {
- t->val--; t->sum -= x;
- remove(t->r, x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement