1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <set> #define init(x) memset (x,0,sizeof (x)) #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f using namespace std; const int MAX = 4e5 + 5; const int MOD = 1e9 + 7; inline int read (); int n,tot,cnt,k[MAX],tree[MAX << 2]; struct node { char ty[10]; int x,y; } q[MAX]; set <int> s[MAX]; void modify (int cur,int l,int r,int x,int v); int query (int cur,int l,int r,int x,int y,int v); int main () { n = read (); for (int i = 1;i <= n;++i) scanf ("%s",q[i].ty),q[i].x = read (),q[i].y = read (),k[++cnt] = q[i].x,k[++cnt] = q[i].y; sort (k + 1,k + 1 + cnt); tot = unique (k + 1,k + cnt + 1) - k - 1; for (int i = 1;i <= n;++i) { q[i].x = lower_bound (k + 1,k + 1 + tot,q[i].x) - k; q[i].y = lower_bound (k + 1,k + 1 + tot,q[i].y) - k; } for (int i = 1;i <= n;++i) { if (q[i].ty[0] == 'a') s[q[i].x].insert (q[i].y),modify (1,1,tot,q[i].x,*(--s[q[i].x].end ())); else if (q[i].ty[0] == 'r') { s[q[i].x].erase (q[i].y); if (!s[q[i].x].size ()) modify (1,1,tot,q[i].x,0); else modify (1,1,tot,q[i].x,*(--s[q[i].x].end ())); } else { int pos = query (1,1,tot,q[i].x + 1,tot,q[i].y); if (pos == -1) puts ("-1"); else printf ("%d %d\n",k[pos],k[*s[pos].upper_bound (q[i].y)]); } } return 0; } inline int read () { int s = 0;int f = 1; char ch = getchar (); while ((ch < '0' || ch > '9') && ch != EOF) { if (ch == '-') f = -1; ch = getchar (); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar (); } return s * f; } void modify (int cur,int l,int r,int x,int v) { if (l == r) { tree[cur] = v; return ; } int mid = (l + r) >> 1; if (x <= mid) modify (cur << 1,l,mid,x,v); else modify (cur << 1 | 1,mid + 1,r,x,v); tree[cur] = max (tree[cur << 1],tree[cur << 1 | 1]); } int query (int cur,int l,int r,int x,int y,int v) { if (tree[cur] <= v || y < l || x > r) return -1; if (l == r) return l; int mid = (l + r) >> 1,s = query (cur << 1,l,mid,x,y,v); if (~s) return s; return query (cur << 1 | 1,mid + 1,r,x,y,v); }
|