namespace tr { structnode { int ls, rs; multiset<int> s; }a[N*2]; int lim, root, node_cnt; voidbuild(int &i = root, int l = 1, int r = lim); voiderase(int x, int y, int i = root, int l = 1, int r = lim); voidinsert(int x, int y, int i = root, int l = 1, int r = lim); pair<int,int> find(int x, int y, int i = root, int l = 1, int r = lim); }
char opt[N][8]; int x[N], y[N]; int lsh[N], lcnt;
intmain() { int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> opt[i] >> x[i] >> y[i]; lsh[i] = x[i]; } sort(lsh+1, lsh+n+1); lcnt = unique(lsh+1, lsh+n+1)-lsh-1; for(int i = 1; i <= n; i++) x[i] = lower_bound(lsh+1, lsh+lcnt+1, x[i])-lsh; tr::lim = lcnt; tr::build(); for(int i = 1; i <= n; i++) { if(opt[i][0] == 'a') tr::insert(x[i], y[i]); elseif(opt[i][0] == 'r') tr::erase(x[i], y[i]); else { x[i] += 1, y[i] += 1; if(x[i] > lcnt) { cout << "-1\n"; continue; } auto ans = tr::find(x[i], y[i]); ans.first = lsh[ans.first]; if(ans.second != INF) cout << ans.first << " " << ans.second << "\n"; else cout << "-1\n"; } } } namespace tr { #define ls(i) a[i].ls #define rs(i) a[i].rs #define lmid ((l+r)>>1) #define rmid ((l+r+2)>>1) voidbuild(int &i, int l, int r) { i = ++node_cnt; if(l == r) returnvoid(); build(ls(i), l, lmid); build(rs(i), rmid, r); } voidinsert(int x, int y, int i, int l, int r) { a[i].s.insert(y); if(l == r) returnvoid(); if(x <= lmid) insert(x, y, ls(i), l, lmid); if(x >= rmid) insert(x, y, rs(i), rmid, r); } voiderase(int x, int y, int i, int l, int r) { auto it = a[i].s.lower_bound(y); a[i].s.erase(it); if(l == r) returnvoid(); if(x <= lmid) erase(x, y, ls(i), l, lmid); if(x >= rmid) erase(x, y, rs(i), rmid, r); } pair<int,int> find(int x, int y, int i, int l, int r) { if(l == r) { auto it = a[i].s.lower_bound(y); if(it != a[i].s.end()) return {l, *it}; else return {l, INF}; } auto &ls_s = a[ls(i)].s, &rs_s = a[rs(i)].s; if(x <= lmid and ls_s.lower_bound(y) != ls_s.end()) { auto tmp = find(x, y, ls(i), l, lmid); if(tmp.second != INF) return tmp; } if(rs_s.lower_bound(y) != rs_s.end()) returnfind(x, y, rs(i), rmid, r); else return {114514, INF}; } }