func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000;   int a[300005], b[300005];   class SegmentTree {    public:     SegmentTree* left = nullptr;     SegmentTree* right = nullptr;     int start, end, val = 0, lazyadd = 0;     SegmentTree(int s, int e) {       start = s;       end = e;       if (start != end) {         left = new SegmentTree(start, (start + end) / 2);         right = new SegmentTree((start + end) / 2 + 1, end);       }     }     void propogate() {       if (lazyadd) {         left->val += lazyadd;         right->val += lazyadd;         left->lazyadd += lazyadd;         right->lazyadd += lazyadd;         lazyadd = 0;       }     }     void update(int l, int r, int v) {       if (l > end || r < start) {         return;       }       if (l <= start && end <= r) {         val += v;         lazyadd += v;         return;       }       propogate();       left->update(l, r, v);       right->update(l, r, v);       val = min(left->val, right->val);     }     int traverse() {       if (val >= 0) {         return -1;       }       if (start == end) {         return start;       }       propogate();       if (right->val < 0) {         return right->traverse();       }       return left->traverse();     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     int n, m, q, input;     int index, x;     cin >> n >> m;     SegmentTree myTree(1, 1000000);     for (int i = 1; i <= n; i++) {       cin >> a[i];       myTree.update(1, a[i], -1);     }     for (int j = 1; j <= m; j++) {       cin >> b[j];       myTree.update(1, b[j], 1);     }     cin >> q;     for (int w = 0; w < q; w++) {       cin >> input >> index >> x;       if (input == 1) {         myTree.update(1, a[index], 1);         a[index] = x;         myTree.update(1, a[index], -1);       } else {         myTree.update(1, b[index], -1);         b[index] = x;         myTree.update(1, b[index], 1);       }       cout << myTree.traverse() << endl;     }     return 0;   }   