树状数组套 set 两个老哥死活过不去了。求路过懂爷帮忙卡卡常。
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (register int i = (a); i <= (b); i ++ )
#define rop(i, a, b) for (register int i = (a); i < (b); i ++ )
using namespace std;
#define gc getchar
#define pc putchar
void read() { return; }
template <typename T, typename ...T2>
void read(T &s, T2 &...oth) {
s = 0; char ch = gc(); bool f = 0;
for (; ch < '0' or ch > '9'; ch = gc()) if (ch == '-') f = 1;
for (; ch >= '0' and ch <= '9'; ch = gc()) s = (s << 1) + (s << 3) + (ch ^ 48);
s = f ? -s : s; read(oth...); return;
}
void write(char ch) { return; }
template <typename T, typename ...T2>
void write(char ch, T s, T2 ...oth) {
if (!s) { pc('0'); pc(ch); write(ch, oth...); return; }
int stk[100], top = 0;
if (s < 0) pc('-'), s = ~s + 1;
while (s) stk[ ++ top] = s % 10, s /= 10;
do pc(stk[top -- ] + (1 << 4) + (1 << 5)); while (top);
pc(ch); write(ch, oth...); return;
}
typedef pair<int, int> PII;
const int N = 200010;
const int INF = 0x3f3f3f3f;
set<PII> s[N]; vector<int> p;
int n, lim;
struct Q {
int op, x, y;
}q[N];
void add(int x, int y) {
for (int i = y; i; i -= (i & -i))
s[i].insert(mp(x, y));
}
void del(int x, int y) {
for (int i = y; i; i -= (i & -i))
s[i].erase(mp(x, y));
}
PII ask(int x, int y) {
PII ans = mp(INF, INF);
for (int i = y; i <= lim; i += (i & -i))
ans = min(ans, *s[i].lower_bound(mp(x, y)));
return ans;
}
int main() {
read(n);
rep(i, 1, n) {
char ch[7]; int x, y;
scanf("%s", ch); read(x, y);
if (*ch == 'a') q[i] = {0, x, y};
if (*ch == 'r') q[i] = {1, x, y};
if (*ch == 'f') q[i] = {2, ++ x, ++ y};
p.push_back(y);
} sort(all(p)); p.resize(unique(all(p)) - p.begin());
lim = p.size();
auto find = [](int x) -> int {
return lower_bound(all(p), x) - p.begin() + 1;
};
rep(i, 1, n) q[i].y = find(q[i].y);
rep(i, 1, lim) s[i].insert(mp(INF, INF));
rep(i, 1, n) {
if (q[i].op == 0) add(q[i].x, q[i].y);
if (q[i].op == 1) del(q[i].x, q[i].y);
if (q[i].op == 2) {
register PII ans = ask(q[i].x, q[i].y);
if (ans.first == INF) puts("-1");
else write(' ', ans.first, p[ans.second - 1]), pc('\n');
}
} return 0;
}