Question link: Click the open link
The minimum x value for maintaining the y value greater than the val value in the line segment tree
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define inf 1000000010 # define ll int # define N 200005 # define L (x) (x <1) # define R (x) (x <1 | 1) inline ll Mid (ll a, ll B) {return (a + B)> 1 ;}ll n; struct node {ll x, y; node (ll a = 0, ll B = 0): x (a), y (B) {} bool operator <(const node &) const {if (. x = x) return. y> y; return. x> x;} ll op;} in [N]; set
Myset; set
: Iterator p; struct Edge {int l, r, id; int maxx, lval; set
St;} tree [N <4]; set
: Iterator pp; set
Lisan; void build (int l, int r, int id) {tree [id]. l = l, tree [id]. r = r; tree [id]. maxx = tree [id]. lval =-1; tree [id]. st. clear (); tree [id]. st. insert (-1); if (l = r) return; int mid = Mid (l, r); build (l, mid, L (id )); build (mid + 1, r, R (id);} void updata (ll pos, ll id, ll val, ll o) {// o = 1 indicates to insert if (tree [id]. l = tree [id]. r) {if (o = 1) {tree [id]. st. insert (val); tree [id]. lval = tree [id]. maxx = max (tree [id]. maxx, val); return;} else tree [id]. st. erase (val); pp = tree [id]. st. end (); pp --; tree [id]. lval = tree [id]. maxx = * pp; return;} ll mid = Mid (tree [id]. l, tree [id]. r); if (mid
Val) return tree [id]. l;} ll mid = Mid (tree [id]. l, tree [id]. r); if (mid
Mp; int main () {ll x, y; while (~ Scanf ("% d", & n) {myset. clear (); mp. clear (); lisan. clear (); for (ll I = 0; I <n; I ++) {char s [10]; scanf ("% s", s ); scanf ("% d", & in [I]. x, & in [I]. y); lisan. insert (in [I]. x); if (s [0] = 'A') in [I]. op = 1; else if (s [0] = 'R') in [I]. op = 2; else in [I]. op = 3;} ll siz = 1; for (pp = lisan. begin (); pp! = Lisan. end (); pp ++) {pos [siz] = * pp; mp. insert (pair
(* Pp, siz); siz ++;} for (ll I = 0; I <n; I ++) in [I]. x = mp. find (in [I]. x)-> second; build (1, siz, 1); for (ll I = 0; I <n; I ++) {x = in [I]. x, y = in [I]. y; if (in [I]. op = 1) {myset. insert (node (pos [x], y); updata (in [I]. x, 1, in [I]. y, 1);} else if (in [I]. op = 2) {myset. erase (node (pos [x], y); updata (in [I]. x, 1, in [I]. y, 0);} else {ll he = query (in [I]. x + 1, siz, 1, in [I]. y); if (he =-1) {puts ("-1"); continue;} printf ("% d \ n", pos [he], myset. lower_bound (node (pos [he], in [I]. y + 1)-> y) ;}} return 0 ;}