评测记录:
https://codeforces.com/contest/19/submission/193998158
第30个点tle
#include<bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
#define int long long
#define gc getchar()
int rd(){
int x = 0, f = 1; char ch = gc;
for (; !isdigit(ch); ch = gc) if(ch == '-') f = -1;
for (; isdigit(ch); ch = gc) x = x*10 + ch - '0';
return x*f;
}
int n, cnt;
set<int> st[2*maxn]; // 竖向
#define ls (x<<1)
#define rs (x<<1|1)
#define mid ((l+r) >> 1)
int mx[maxn<<2];
void pushup(int x){ mx[x] = max(mx[ls], mx[rs]);}
void ad(int x, int l, int r, int dir, int k){
if(l == r) {
mx[x] = max(mx[x], k);
return;
}
if(mid >= dir) ad(ls, l, mid, dir, k);
if(mid < dir) ad(rs, mid+1, r, dir, k);
pushup(x);
}
int fd(int x, int l, int r, int L, int R, int k){
if(mx[x] < k) return -1;
if(l == r){
if(mx[x] <= k) return -1;
return l;
}
int ans = -1;
if(mid >= L) ans = fd(ls, l, mid, L, R, k);
if(ans != -1) return ans;
if(mid < R) return fd(rs, mid+1, r, L, R, k);
return -1;
}
void chg(int x, int l, int r, int dir, int k){
if(l == r) {
mx[x] = k;
return;
}
if(mid >= dir) chg(ls, l, mid, dir, k);
if(mid < dir) chg(rs, mid+1, r, dir, k);
pushup(x);
}
struct node{char ch; int x, y;}q[maxn];
int h[2*maxn];
signed main(){
cin >> n;
string s;
for (int i = 1; i <= n; i++){
cin >> s;
q[i].ch = s[0]; q[i].x = rd(); q[i].y = rd();
h[i*2-1] = q[i].x; h[i*2] = q[i].y;
}
sort(h+1, h+1+2*n);
cnt = unique(h+1, h+1+2*n) - (h+1);
for (int i = 1; i <= n; i++) {
q[i].x = lower_bound(h+1, h+1+cnt, q[i].x) - h;
q[i].y = lower_bound(h+1, h+1+cnt, q[i].y) - h;
}
set<int>::iterator dir;
for (int i = 1; i <= n; i++){
int x = q[i].x, y = q[i].y;
if(q[i].ch == 'a'){
st[x].insert(y);
ad(1,1,cnt, x, y);
}else if(q[i].ch == 'r'){
dir = lower_bound(st[x].begin(), st[x].end(), y);
st[x].erase(dir);
if(st[x].empty()){
chg(1,1,cnt, x, 0);
}else{
chg(1,1,cnt, x, *st[x].rbegin());
}
}else{
if(y == cnt) {cout << -1 << "\n"; continue;}
int nx = fd(1,1,cnt, x+1, cnt, y);
if(nx == -1) {cout << -1 << "\n"; continue;}
dir = upper_bound(st[nx].begin(), st[nx].end(), y);
cout << h[nx] << " " << h[*dir] << "\n";
}
}
return 0;
}