Advertisement
MathQ_

Untitled

Aug 28th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. void insert(Node* &t, Node* &p) {
  2.     if (t == nullptr) {
  3.         t = p;
  4.         return;
  5.     }
  6.     if (p->prior > t->prior) {
  7.         swap(t, p);
  8.         nodepair q = split(p, t->key);
  9.         t->l = q.fi;
  10.         t->r = q.se;
  11.         upd(t);
  12.         return;
  13.     }
  14.     if (p->key <= t->key) {
  15.         t->val++; t->sum += p->key;
  16.         insert(t->l, p);
  17.     } else {
  18.         t->val++; t->sum += p->key;
  19.         insert(t->r, p);
  20.     }
  21. }
  22.  
  23. void remove(Node* &t, int x) {
  24.     if (t->key == x) {
  25.         t = merge(t->l, t->r);
  26.         if (t) upd(t);
  27.         return;
  28.     }
  29.     if (x < t->key) {
  30.         t->val--; t->sum -= x;
  31.         remove(t->l, x);
  32.     } else {
  33.         t->val--; t->sum -= x;
  34.         remove(t->r, x);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement