codeForce-19D Points (点更新+离散化)
题目大意:在二维坐标系的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 (点更新+离散化)的更多相关文章
- POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...
- CodeForces 19D Points(离散化+线段树+单点更新)
题目链接: huangjing 题意:给了三种操作 1:add(x,y)将这个点增加二维坐标系 2:remove(x,y)将这个点从二维坐标系移除. 3:find(x,y)就是找到在(x,y)右上方的 ...
- CodeForces 19D Points(线段树+map)
开始想不通,后来看网上说是set,就有一个想法是对每个x建一个set...然后又想直接建立两重的set就好,最后发现不行,自己想多了... 题意是给你三种操作:add (x y) 平面添加(x y) ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- CF 19D - Points 线段树套平衡树
题目在这: 给出三种操作: 1.增加点(x,y) 2.删除点(x,y) 3.询问在点(x,y)右上方的点,如果有相同,输出最左边的,如果还有相同,输出最低的那个点 分析: 线段树套平衡树. 我们先离散 ...
- POJ2528 Mayor's posters(线段树&区间更新+离散化)题解
题意:给一个区间,表示这个区间贴了一张海报,后贴的会覆盖前面的,问最后能看到几张海报. 思路: 之前就不会离散化,先讲一下离散化:这里离散化的原理是:先把每个端点值都放到一个数组中并除重+排序,我们就 ...
- CodeForces 19D Points (线段树+set)
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- ACM-线段树区间更新+离散化
区间更新与单点更新最大的不同就在于Lazy思想: http://blog.sina.com.cn/s/blog_a2dce6b30101l8bi.html 可以看这篇文章,讲得比较清楚 在具体使用上, ...
随机推荐
- 自定义的dialog
自定义的dialog 其中包含置顶 删除 和取消 下面的是BaseDialog package com.free.csdn.view.dialog; import android.app.Dialo ...
- redis——基础介绍
转自:http://www.cnblogs.com/xing901022/p/4863929.html 1 什么是Redis Redis(REmote DIctionary Server,远程数据字典 ...
- (转)js函数参数设置默认值
原文:http://www.cnblogs.com/RightDear/archive/2013/06/26/3156652.html js函数参数设置默认值 php有个很方便的用法是在定义函数时 ...
- error C3163: “_vsnprintf”: 属性与以前的声明不一致
这是在vs2008中遇到的错误,vs2008以前没有,vs2008以后的vs也没有. c:\program files\microsoft visual studio 9.0\vc\include\s ...
- 通过一个Thinkphp完成多个项目
1.单独取压缩包中的Thinkphp文件夹 2.在单独的项目内创建一个引入文件 3.通过浏览器访问该index.php 会创建相应的目录
- HDOJ-三部曲一(搜索、数学)-1005-Dungeon Master
Dungeon Master Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tot ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- WPF入门教程系列(一) 创建你的第一个WPF项目
WPF入门教程系列(一) 创建你的第一个WPF项目 WPF基础知识 快速学习绝不是从零学起的,良好的基础是快速入手的关键,下面先为大家摞列以下自己总结的学习WPF的几点基础知识: 1) C#基础语法知 ...
- Js运算符优先级
1.. [] {} 提取属性与函数调用 2. delete new typof + - ! 一元运算符 3. * / % 乘法.除法.求余 4. + - 加法/连接.减法 5.>= &l ...
- 解决CSS小于12px的文字在谷歌浏览器显示问题
做前端设计的人经常要接触CSS方面的问题,估计有不少人会遇到Chrome谷歌浏览器中CSS设置字体小于12px显示不正常,强创网络在做magento模板过程中就遇到了,起初以为是自己写的CSS的问题, ...