题目大意:在二维坐标系的x正半轴,y正半轴和第一象限内,有三种操作:

      1、add x,y (添加点<x,y>);

      2、remove x,y(移除点<x,y>);

      3、find x,y(查找在点<x,y>的绝对右上角的第一个点);

并且,只能移除已添加的点,一个点在移除之前不能重复添加。

题目分析:将横坐标离散化,线段树的每个叶子节点维护对应横坐标上的最大纵坐标。非叶子节点维护对应区间内的最大纵坐标。

代码如下:

# 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);
pushUp(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]); ///如果改成上面的就超时了。
printf("%d %d\n",x[l],r);
}
}
}
}
return 0;
}

  

codeForce-19D Points (点更新+离散化)的更多相关文章

  1. POJ-2528 Mayor's posters (线段树区间更新+离散化)

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  2. CodeForces 19D Points(离散化+线段树+单点更新)

    题目链接: huangjing 题意:给了三种操作 1:add(x,y)将这个点增加二维坐标系 2:remove(x,y)将这个点从二维坐标系移除. 3:find(x,y)就是找到在(x,y)右上方的 ...

  3. CodeForces 19D Points(线段树+map)

    开始想不通,后来看网上说是set,就有一个想法是对每个x建一个set...然后又想直接建立两重的set就好,最后发现不行,自己想多了...  题意是给你三种操作:add (x y) 平面添加(x y) ...

  4. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  5. CF 19D - Points 线段树套平衡树

    题目在这: 给出三种操作: 1.增加点(x,y) 2.删除点(x,y) 3.询问在点(x,y)右上方的点,如果有相同,输出最左边的,如果还有相同,输出最低的那个点 分析: 线段树套平衡树. 我们先离散 ...

  6. POJ2528 Mayor's posters(线段树&区间更新+离散化)题解

    题意:给一个区间,表示这个区间贴了一张海报,后贴的会覆盖前面的,问最后能看到几张海报. 思路: 之前就不会离散化,先讲一下离散化:这里离散化的原理是:先把每个端点值都放到一个数组中并除重+排序,我们就 ...

  7. CodeForces 19D Points (线段树+set)

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  8. POJ2528:Mayor's posters(线段树区间更新+离散化)

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  9. ACM-线段树区间更新+离散化

    区间更新与单点更新最大的不同就在于Lazy思想: http://blog.sina.com.cn/s/blog_a2dce6b30101l8bi.html 可以看这篇文章,讲得比较清楚 在具体使用上, ...

随机推荐

  1. Asp.net项目因Session阻塞导致页面打开速度变慢

    发现罪魁祸首是Session阻塞造成的.默认情况下session状态是“可写状态”(EnableSessionState=”true”),即当用户打开任何一个页面时,该页面的Session就会持有一个 ...

  2. CCNA 6.6

    sh run (show running-config) enable disable login logout exit end  enable password privilege level(g ...

  3. eclipse web项目实际工程路径对应

    src/1.properties ---->实际路径 /WEB-INF/classes/1.propertiessrc/com.ayong.one/2.properties /WEB-INF/c ...

  4. 更新安装xcode7插件

    mkdir -p ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-inscurl -fsSL https://raw.github ...

  5. cf--2A

    //Accepted 100 KB 92 ms //模拟 #include <cstdio> #include <cstring> #include <iostream& ...

  6. java多线程的协作

    java多线程之间相互协作,主要有join,  yield,  interupt(),  sleep,  wait,  notify,  notifyAll; join: 在一个线程A的代码里面调用另 ...

  7. VS调试Ajax

    VS调试Ajax: 1.ashx在后台处理程序中设定断点 2.触发AJAX 3.F12打开浏览器调试,搜索找到ajax调用的JS,设置断点,在浏览器中单步调试,会自动进入后台处理程序,然后就可以调试后 ...

  8. [super init]方法的调用

    当重新覆盖父类的init方法时,需要调用[super init]方法确认父类中的init是返回一个实例,而不是一个空的实例. 那为什么要调用这个呢? 我得猜测是这样的:因为这是一个初始化方法,需要对对 ...

  9. Qemu+gdb跟踪内核源码

    1.编译安装Qemu Qemu源码下载地址:http://wiki.qemu.org/Download linux下可以直接用wget下载: wget http://wiki.qemu.org/dow ...

  10. magento问题集3

    MISSING LANGUAGE FILES OR DIRECTORIES A:已经装了俄语包,也是russian目录,在前台也可以用.但是在后台最上面总是显示MISSING LANGUAGE FIL ...