Test instructions: Test instructions is well understood, three operations: (1) Add x y, adding coordinates (x, y), (2) del x y, delete coordinates (x, y), (3) Find x y, find and output the minimum coordinates in a strictly greater than (x, y) coordinate.
The main point: because there are 200,000 points, and the point coordinates up to 1e9, so to discretization, we only need to discretization of x, then each x corresponding to a set to save Y, and then each time you modify the operation, according to the value within the set to maintain the maximum Y.
#include <cstdio>#include <cstring>#include <set>#include <algorithm>using namespace STD;Const intN =200100;structPoint {intx, y; Point (intA =-1,intb =-1): X (a), Y (b) {}}p[n]; Set<int>Py[n];structTree {intMAXP;} Tree[n <<2];intN, Num[n], res;Charstr[n][Ten];voidBuildintKintLeftintright) {Tree[k].maxp =-1;if(Left! = right) {intMid = (left + right)/2; Build (k *2, left, mid); Build (k *2+1, Mid +1, right); }}voidPushup (intK) {TREE[K].MAXP = max (Tree[k *2].MAXP, Tree[k *2+1].MAXP);}voidModifyintKintLeftintRightintPOS) {if(left = right) {if(Py[pos].size ()) Tree[k].maxp = * (--py[pos].end ());ElseTREE[K].MAXP =-1;return; }intMid = (left + right)/2;if(POS <= mid) modify (k *2, left, Mid, POS);ElseModify (k *2+1, Mid +1, right, POS); Pushup (k);}voidQueryintKintLeftintRightintPosintP) {if(Right <= POS)return;if(Tree[k].maxp <= p)return;if(left = right) {res = left;return; }intMid = (left + right)/2; Query (k *2, left, Mid, POS, p);if(res = =-1) Query (k *2+1, Mid +1, right, POS, p);}intMain () {scanf("%d", &n);intCNT =0; for(inti =1; I <= N; i++) {scanf("%s%d%d", Str[i], &p[i].x, &P[I].Y);if(str[i][0] ==' A ') num[++cnt] = p[i].x; } sort (num +1, Num +1+ CNT); CNT = unique (num +1, Num +1+ CNT)-(num +1); for(inti =1; I <= CNT; i++) py[i].clear ();if(CNT = =0) tree[1].MAXP =-1;ElseBuild1,1, CNT); for(inti =1; I <= N; i++) {intpos = upper_bound (num +1, Num +1+ CNT, p[i].x)-(num +1);if(str[i][0] ==' A ') {Py[pos].insert (P[I].Y); Modify1,1, CNT, POS); }Else if(str[i][0] ==' R ') {py[pos].erase (P[I].Y); Modify1,1, CNT, POS); }Else{res =-1;if(POS <= cnt) query (1,1, CNT, POS, P[I].Y);if(res = =-1)printf(" -1\n");Else printf("%d%d\n", Num[res], *py[res].upper_bound (P[I].Y)); } }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 19D (segment tree + discretization)