CF#19D:http://codeforces.com/contest/19/problem/D

题意:给你一个点,add x,y表示向集合中添加一个点,remove x,y,表示删除集合中的一个点,find x,y,表示查询比x,y,严格大的点,没有输出-1.

题解;这一题是一道好题,我从中学到了很多东西。首先,这一题的正解是线段树+set。首先按照x值建树,set[i]维护的是x值是i的所有y的集合。同时线段树还维护一个最大值maxn。首先,是离散化。这里用map和vector巧妙的实现了,map[xx[i]]=i;即可。其次是set,当查询dao一个满足条件的x值的时候,要查询y值的时候,可以使用lower_bound来实现。还有就是,线段树的查询,与往常的查询不太一样,以前都是查询某个点的值,这里是查询比两个值大的区间端点,不是一个。最后就是,用vecotr去重的写法:xx.erase(unique(xx.begin(),xx.end()),xx.end());

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
int n;
map<int,int>Map;
const int N=*1e5+;
vector<int>xx;
struct action{
int x;
int y;
char str[];
void add(){
xx.push_back(x);
}
}OP[N];
struct Node{
int l,r;
int maxn;
inline int mid(){
return (l+r)/;
}
}num[N*];
void pushup(int rt){
num[rt].maxn=max(num[rt<<].maxn,num[rt<<|].maxn);
}
set<int>yy[N];
void build(int l,int r,int rt){
num[rt].l=l;
num[rt].r=r;
num[rt].maxn=-;
if(l==r){
yy[l].clear();
return;
}
int mid=(l+r)/;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
}
void insert(int pos,int y,int rt){
if(num[rt].l==num[rt].r){
yy[pos].insert(y);
num[rt].maxn=*(--yy[pos].end());
return;
}
int mid=num[rt].mid();
if(mid>=pos)insert(pos,y,rt<<);
else insert(pos,y,rt<<|);
pushup(rt);
}
void remove(int pos,int y,int rt){
if(num[rt].l==num[rt].r){
yy[pos].erase(y);
if(yy[pos].size()==)num[rt].maxn=-;
else
num[rt].maxn=*(--yy[pos].end());
return;
}
int mid=num[rt].mid();
if(mid>=pos)remove(pos,y,rt<<);
else remove(pos,y,rt<<|);
pushup(rt);
}
Node query(int y,int rt,int x){
if(num[rt].maxn<y||num[rt].r<x){
Node t1;
t1.l=-;
return t1;
}
if(num[rt].l==num[rt].r){
Node tt;
tt.l=num[rt].l;
tt.r=*yy[num[rt].l].lower_bound(y);
return tt;
}
Node tp=query(y,rt<<,x);
if(tp.l!=-)return tp;
return query(y,rt<<|,x);
} int main(){
while(~scanf("%d",&n)){
xx.clear();Map.clear();
for(int i=;i<n;i++){
scanf("%s%d%d",OP[i].str,&OP[i].x,&OP[i].y);
OP[i].add();
}
sort(xx.begin(),xx.end());
xx.erase(unique(xx.begin(),xx.end()),xx.end());
int len=xx.size();
for(int i=;i<len;i++)
Map[xx[i]]=i;
build(,len-,);
for(int i=;i<n;i++){
if(OP[i].str[]=='a')
insert(Map[OP[i].x],OP[i].y,);
else if(OP[i].str[]=='r')
remove(Map[OP[i].x],OP[i].y,);
else {
Node ans=query(OP[i].y+,,Map[OP[i].x]+);
if(ans.l==-)printf("-1\n");
else
printf("%d %d\n",xx[ans.l],ans.r);
}
}
}
}

Points的更多相关文章

  1. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  2. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  3. LeetCode:Max Points on a Line

    题目链接 Given n points on a 2D plane, find the maximum number of points that lie on the same straight l ...

  4. K closest points

    Find the K closest points to a target point in a 2D plane. class Point { public int x; public int y; ...

  5. 【leetcode】Max Points on a Line

    Max Points on a Line 题目描述: Given n points on a 2D plane, find the maximum number of points that lie ...

  6. Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  7. [LeetCode OJ] Max Points on a Line

    Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...

  8. [UCSD白板题] Points and Segments

    Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...

  9. [UCSD白板题] Covering Segments by Points

    Problem Introduction You are given a set of segments on a line and your goal is to mark as few point ...

  10. [javascript svg fill stroke stroke-width points polygon属性讲解] svg fill stroke stroke-width points polygon绘制多边形属性并且演示polyline和polygon区别讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

随机推荐

  1. js判断字符串是否包含指定的字符

    判断字符串是否包含指定字符是很常用的功能,比如说,注册时用户名限制不能输入"管理员",或者需要js判断url跳转链接是否包含某个关键词等-- <!DOCTYPE html&g ...

  2. throw与throw的区别

    Throwable 是所有 Java 程序中错误处理的父类 ,有两种资类: Error 和 Exception . Error :表示由 JVM 所侦测到的无法预期的错误,由于这是属于 JVM 层次的 ...

  3. SAP-MM:发票、贷方凭证、事后借记、后续贷记

    发票和事后借记 相同点:增加对供应商的应付款 不同点:针对同一订单收货,发票要先于事后借记(事后借记是对供应商后期发票金额的补充):发票和金额.订单数量有关系,而事后借记只是订单金额调整的凭证,仅仅是 ...

  4. CentOS 安装 Tomcat

    1.Tomcat官网获(http://tomcat.apache.org/)取tar.gz文件的下载地址 2.下载: # wget http://apache.fayea.com/tomcat/tom ...

  5. Java注解的简单了解

    部分信息来自<Thinking In Java> 注解也成为元数据.什么是元数据?就是“关于数据的数据” 注解为我们在代码中添加信息提供了一种形式化的方法,使我们可以在稍后某个时刻非常方便 ...

  6. [转] Linux文件系统之hard link&symbol link

    这个图很清楚的表示出硬链接和软链接的方式. 1.硬链接: 基本定义:硬链接是有着相同inode号的仅文件名不同的文件(该文件名包含路径信息). 理解:如图,hard link和原始file通过同一个i ...

  7. CSRF跨站点请求伪造漏洞问题

    最近在写php,项目写完后送检发现一个漏洞问题CSRF,强行拖了我一天的时间,沉迷解决问题,茶饭不思,日渐消瘦,时间比较赶,这篇比较糙,凑合看下. 好了废话不多说下面是今天的解决方案. 博主用的是Th ...

  8. 9.16noip模拟试题

    题目描述 在幻想乡,东风谷早苗是以高达控闻名的高中生宅巫女.某一天,早苗终于入手了最新款的钢达姆模型.作为最新的钢达姆,当然有了与以往不同的功能了,那就是它能够自动行走,厉害吧(好吧,我自重).早苗的 ...

  9. ASP.NET-FineUI开发实践-15

    1.按条件控制Grid不可编辑     Grid编辑其实用到的不多...但是也有要控制权限或者其他条件不能编辑的情况其实挺简单,学过extjs的知道,我现在也只是写前台了,没有写到后台事件,有时间再说 ...

  10. 二维码生成Demo

    在C#中直接引用ThoughtWorks.QRCode.dll 类, 下载 dll 类 http://file.111cn.net/download/2013/06/29/20120516165420 ...