Codeforces 19D Points (segment tree +map)

Source: Internet
Author: User
Tags mul

Start to think about, and then look at the online said is set, there is an idea is to build a set for each x ... And then want to directly set up a double set on the good, finally found no, I think more ...
Test instructions is giving you three operations: Add (x y) plane adds (x y) this point
Remove (x y) plane Delete (x y) this point
Find (x Y) finds (x y) This point is strictly the leftmost point in the upper right, and there are multiple to find the bottom point, output

Actually figured out or relatively simple, my idea is to sort x first and then y sort, so build a line tree, the use is: Add and delete can be used as a single point of update, only need to record the maximum value is good. When finding a position greater than x with the map's Upper_bound (), you can search directly from top to bottom in the range that is greater than the current Y value (the maximum value is used here), because it is sorted so that it is the smallest of the top. But the scope is too large to be discretized, I use map discretization, another two-dimensional map to find the current point is the first point in the tree.
Note that when there is no add operation, you cannot make a contribution because this will result in Create (1,0,1) ... I thought the map was jammed.

#include <Set>#include<map>#include<queue>#include<stack>#include<cmath>#include<vector>#include<string>#include<cstdio>#include<cstring>#include<stdlib.h>#include<iostream>#include<algorithm>using namespacestd;#defineEPS 1E-8/*Note that there may be output -0.000*/#defineSGN (x) (X<-eps -1:x<eps? 0:1)//X is a comparison of two floating-point numbers, note the return integer#defineCvs (x) (x > 0.0 x+eps:x-eps)//floating point Conversion#defineZero (x) (((x) >0? ( x):-(x)) <eps)//determine if it equals 0#defineMul (A, B) (a<<b)#defineDir (A, B) (a>>b)typedefLong Longll;typedef unsignedLong LongUll;typedef pair<int,int>PII;Const intinf=1<< -;Const DoublePi=acos (-1.0);Const intmax=200010;Const intMax2=200010<<2;Charstr[max][Ten];intXx1[max],yy1[max],nnow;map<int,int> MPOs;//find the first leftmost position greater than the desired valueMAP&LT;PII,int> MP;//discretization ofMAP&LT;PII,int>:: Iterator It;map<int,int>:: iterator IIT;intSegtr[max2],tem[max2],ans,flag;intNmaxintAintb) {    returnA>b?a:b;}voidUpnow (intNowintnext) {Segtr[now]=nmax (segtr[next],segtr[next|1]); return;}voidCreate (intStaintEnnintNow ) {    if(sta==enn) {Segtr[now]=-1; return; }    intMid=dir (Sta+enn,1); intNext=mul (now,1);    Create (Sta,mid,next); Create (Mid+1, enn,next|1);    Upnow (Now,next); return;}voidUpdate (intStaintEnnintNowintXinty) {    if(sta==enn&&sta==x) {Segtr[now]=y; Nnow=Now ; return; }    intMid=dir (Sta+enn,1); intNext=mul (now,1); if(mid>=x) Update (sta,mid,next,x,y); ElseUpdate (Mid+1, enn,next|1, x, y);    Upnow (Now,next); return;}voidQuery (intStaintEnnintNowintXintY//find the first value in the range greater than Y (basic can be considered as the minimum value){    if(sta==enn) {ans=Now ; Flag=0; return; }    intMid=dir (Sta+enn,1); intNext=mul (now,1); if(flag&&mid>=x&&segtr[next]>y)//It's a guaranteed efficiency here.Query (sta,mid,next,x,y); if(flag&&segtr[next|1]>y) Query (Mid+1, enn,next|1, x, y); return;}intMain () {intN,coun;  while(~SCANF ("%d",&N)) {Nnow=0; Coun=1;        Mpos.clear ();        Mp.clear ();  for(intI=0; i<n;i++) {scanf ("%s%d%d",str[i],&xx1[i],&Yy1[i]); if(str[i][0] =='a') {Mp[make_pair (Xx1[i],yy1[i])]=0;//Two-dimensional map        }        }         for(It=mp.begin (); It!=mp.end (); + +it) {It->second=coun++;//the two-dimensional map storage should be the first node on the tree            if(!mpos.count (it->first.first)) Mpos[it->first.first]=coun-1; } Coun--; if(Coun)//Be sure to pay attention to count>0.Create (1, Coun,1);  for(intI=0; i<n;i++)        {        if(str[i][0] =='a') {Update (1, Coun,1, Mp[make_pair (Xx1[i],yy1[i])],yy1[i]); Tem[nnow]=Xx1[i]; }        Else if(str[i][0] =='R') {Update (1, Coun,1, Mp[make_pair (Xx1[i],yy1[i])],-1); Tem[nnow]=Xx1[i]; }        Else{ans=-1; Flag=1; IIT=Mpos.upper_bound (Xx1[i]); if(iit==Mpos.end ()) {printf ("-1\n"); Continue; } Query (1, Coun,1,iit->Second,yy1[i]); if(ans==-1) printf ("-1\n"); Elseprintf ("%d%d\n", Tem[ans],segtr[ans]); }        }    }    return 0;}

Codeforces 19D Points (segment tree +map)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.