The main problem: in the two-dimensional coordinate system x positive half axis, y positive half axis and the first quadrant, there are three kinds of operations:
1, add x, y (adding point <x,y>);
2, remove X, y (remove point <x,y>);
3. Find x, Y (find the first point in the absolute upper-right corner of Point <x,y>);
Also, only points that have been added can be removed, and a point cannot be added again until it is removed.
Problem Analysis: The horizontal axis is discretized, each leaf node of the segment tree maintains the maximum ordinate at the corresponding horizontal axis. The non-leaf node maintains the maximum ordinate in the corresponding interval.
The code is as follows:
# include<cstdio># include<algorithm># include<map># include<set># include<iostream> Using namespace std;# define MID (L + (R-L)/2) const int N=200000;set<int>s[n+5];char cd[n+5];int A[n+5],b[n+5];char Str[7];int x[n+5];int tr[n*4+5];void pushup (int rt) {Tr[rt]=max (tr[rt<<1],tr[rt<<1|1]);} void build (int rt,int l,int r) {tr[rt]=-1;if (l==r) return; build (rt<<1,l,mid); build (rt<<1|1,mid+1,r);} void update (int rt,int l,int r,int x) {if (l==r) {if (S[l].empty ()) Tr[rt]=-1;else tr[rt]=* (--s[l].end ());} Else{if (x<=mid) update (RT<<1,L,MID,X); else update (RT<<1|1,MID+1,R,X);P ushup (RT);}} int query (int rt,int l,int r,int x,int val) {if (tr[rt]<=val) return-1;if (l==r) {return l;} Else{if (x<=mid) {int k=query (rt<<1,l,mid,x,val); if (k!=-1) return k;} return query (Rt<<1|1,mid+1,r,x,val);}} int main () {int n;while (~scanf ("%d", &n)) {for (int i=0;i<n;++i) {scanf ("%s%d%d", str,a+i,b+i); Cd[i]=str[0];x[i] =a[i];} Sort (x,x+n); int M=uniqUE (X,X+N)-x;for (int i=0;i<=m;++i) s[i].clear (); for (int i=0;i<n;++i) {int Pos=lower_bound (x,x+m , A[i])-x;if (cd[i]== ' a ') {S[pos].insert (b[i]); update (1,0,M,POS);} else if (cd[i]== ' R ') {S[pos].erase (b[i]); update (1,0,M,POS);} Else{int l=query (1,0,m,pos+1,b[i]); if (l==-1) printf (" -1\n"); else{///int R=*upper_bound (S[l].begin (), s[ L].end (), b[i]); int r=*s[l].upper_bound (b[i]); If you change it to the top, it will expire. printf ("%d%d\n", x[l],r);}}} return 0;}
codeforce-19d Points (point update + discretization)