func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long MaxN = 600005;   template <class t>   inline void rd(t &s) {     s = 0;     register char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     return;   }   long long a[MaxN], b[MaxN], vis[MaxN * 3];   struct Quetion {     long long idx, pos, val;   } que[MaxN];   struct SegTree {     struct Node {       long long val, lazy;     };     Node tr[MaxN << 2];     inline void clear() {       memset(tr, 0, sizeof tr);       return;     }     inline void pushup(long long u) {       tr[u].val = max(tr[(u << 1)].val, tr[(u << 1 | 1)].val);       return;     }     inline void pushdown(long long u, long long l, long long r) {       if (tr[u].lazy) {         tr[(u << 1)].lazy += tr[u].lazy;         tr[(u << 1 | 1)].lazy += tr[u].lazy;         tr[(u << 1)].val += tr[u].lazy;         tr[(u << 1 | 1)].val += tr[u].lazy;         tr[u].lazy = 0;       }       return;     }     inline void buildtr(long long u, long long l, long long r) {       if (l == r) {         tr[u].val = 0;         return;       }       register long long mid = (l + r) >> 1;       buildtr((u << 1), l, mid);       buildtr((u << 1 | 1), mid + 1, r);       pushup((u >> 1));       return;     }     inline void change(long long u, long long l, long long r, long long ql,                        long long qr, long long x) {       if (ql == l && r == qr) {         tr[u].val += x;         tr[u].lazy += x;         return;       }       if (l == r) return;       register long long mid = (l + r) >> 1;       pushdown(u, l, r);       if (qr <= mid)         change((u << 1), l, mid, ql, qr, x);       else if (mid < ql)         change((u << 1 | 1), mid + 1, r, ql, qr, x);       else {         change((u << 1), l, mid, ql, mid, x);         change((u << 1 | 1), mid + 1, r, mid + 1, qr, x);       }       pushup(u);       return;     }     inline long long query(long long u, long long l, long long r, long long ql,                            long long qr) {       if (l == r) return l;       register long long mid = (l + r) >> 1;       pushdown(u, l, r);       if (tr[(u << 1 | 1)].val > 0)         return query((u << 1 | 1), mid + 1, r, ql, qr);       else         return query((u << 1), l, mid, ql, qr);     }   } segtree;   signed main(void) {     long long n, m, q;     register long long cnt = 0;     rd(n);     rd(m);     for (long long i = 1; i <= n; ++i) rd(a[i]), vis[++cnt] = a[i];     for (long long i = 1; i <= m; ++i) rd(b[i]), vis[++cnt] = b[i];     rd(q);     for (long long i = 1; i <= q; ++i) {       rd(que[i].idx);       rd(que[i].pos);       rd(que[i].val);       vis[++cnt] = que[i].val;     }     sort(vis + 1, vis + cnt + 1);     cnt = unique(vis + 1, vis + cnt + 1) - vis - 1;     for (long long i = 1; i <= n; ++i)       a[i] = lower_bound(vis + 1, vis + cnt + 1, a[i]) - vis;     for (long long i = 1; i <= m; ++i)       b[i] = lower_bound(vis + 1, vis + cnt + 1, b[i]) - vis;     for (long long i = 1; i <= q; ++i)       que[i].val = lower_bound(vis + 1, vis + cnt + 1, que[i].val) - vis;     segtree.buildtr(1, 1, cnt);     for (long long i = 1; i <= n; ++i) segtree.change(1, 1, cnt, 1, a[i], 1);     for (long long i = 1; i <= m; ++i) segtree.change(1, 1, cnt, 1, b[i], -1);     for (long long i = 1; i <= q; ++i) {       if (que[i].idx == 1) {         segtree.change(1, 1, cnt, 1, a[que[i].pos], -1);         a[que[i].pos] = que[i].val;         segtree.change(1, 1, cnt, 1, a[que[i].pos], 1);       } else {         segtree.change(1, 1, cnt, 1, b[que[i].pos], 1);         b[que[i].pos] = que[i].val;         segtree.change(1, 1, cnt, 1, b[que[i].pos], -1);       }       if (segtree.tr[1].val <= 0)         puts( -1 );       else         printf( %lld n , vis[segtree.query(1, 1, cnt, 1, cnt)]);     }     return 0;   }   