题目大意:在二维坐标系的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. English test for certificate

    <英语口译全真试题精解> GPA 3.5 (MTI)  (CPA) ( GRE )  1350分+3.5以上 SAT ( TOEFL )  100分以上 TOEIC BEC (剑桥商务英语 ...

  2. SrcollView分页加载数据(MainActivity)

    package com.baidu.mylistscroll; import java.util.ArrayList;import java.util.List; import com.baidu.a ...

  3. Matlab单一变量曲线拟合-cftool

    2.启动曲线拟合工具箱>cftool 3.进入曲线拟合工具箱界面“Curve Fitting tool”(1)点击“Data”按钮,弹出“Data”窗口:(2)利用X data和Y data的下 ...

  4. 关于GSMMAP分支cell_log扫描不正常问题的解决办法

    阔别多年,本周在KALI 2.0下重拾旧时趣味,可怎么折腾都未曾见ARFCN,迫不得已还刷了brust_ind分支 才达到目的.后经仔细翻阅官方文档发现此问题早有披露,解决方案也已经公布,逐分享给大家 ...

  5. Planning for a period of time

    After a period of struggle , i decided to follow the teacher Chen learning . Say true i really disli ...

  6. HttpWebRequest 和HttpWebResponse总结

    1. 总结 总结2 3. Code using System; using System.Collections.Generic; using System.Linq; using System.Te ...

  7. windows系统mysql定时自动备份

    MySQL Administrator 工具是MySQL官方的数据库管理工具,包含在MySQL GUI Tools中,可在MySQL官方网站下载到,下载地址:http://dev.mysql.com/ ...

  8. Entityframework更新数据和插入数据

    public bool UpdateEmloyeeInfo(EmployeInfo employeInfo) { bool flg = false; try { using (UserManageDB ...

  9. LinearLayout 控件

    LinearLayout 控件,垂直显示各控件一行一个显示,比较好控件. 用RelativeLayout多个控件会堆在一起 <LinearLayout xmlns:android="h ...

  10. "Your local changes to the following files would be overwritten by merge" on git

    运行: git merge --ff origin/master 得到错误信息: error: Your local changes to the following files would be o ...