开始想不通,后来看网上说是set,就有一个想法是对每个x建一个set。。。然后又想直接建立两重的set就好,最后发现不行,自己想多了。。。 
  题意是给你三种操作:add (x y) 平面添加(x y)这个点 
remove (x y)平面删除(x y)这个点 
find (x y) 查找(x y)这个点严格的右上方中最左边的点,有多个就再找最下方的点,输出

  其实想通了还是比较简单的,我的想法就是对于x先排序再对y排序,这样建一颗线段树,用处在于:添加和删除都可以当成单点更新,只需要记录最大值就好。find时当用map的upper_bound()找到大于x的位置时,可以直接自顶向下搜到范围内大于当前y值(最大值就在这儿用)得最靠前的位置,因为是排序了的,所以最靠前最小。但是范围太大得离散化,我用的是map离散化,另一个二维map找到当前点是树上的第几个点。 
  注意这儿当没有添加操作时,不能建树,因为这样就会出现 Create(1,0,1)。。。一直爆空间,我还以为map被卡了

#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 namespace std;
#define eps 1E-8
/*注意可能会有输出-0.000*/
#define Sgn(x) (x<-eps? -1 :x<eps? 0:1)//x为两个浮点数差的比较,注意返回整型
#define Cvs(x) (x > 0.0 ? x+eps : x-eps)//浮点数转化
#define zero(x) (((x)>0?(x):-(x))<eps)//判断是否等于0
#define mul(a,b) (a<<b)
#define dir(a,b) (a>>b)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int ,int > pii;
const int Inf=<<;
const double Pi=acos(-1.0);
const int Max=;
const int Max2=<<;
char str[Max][];
int xx1[Max],yy1[Max],nnow;
map<int,int> mpos;//找到第一个大于需要值的最左边的位置
map<pii,int> mp;//离散化
map<pii,int>::iterator it;
map<int,int>::iterator iit;
int segtr[Max2],tem[Max2],ans,flag;
int nmax(int a,int b)
{
return a>b?a:b;
}
void Upnow(int now,int next)
{
segtr[now]=nmax(segtr[next],segtr[next|]);
return;
}
void Create(int sta,int enn,int now)
{
if(sta==enn)
{
segtr[now]=-;
return;
}
int mid=dir(sta+enn,);
int next=mul(now,);
Create(sta,mid,next);
Create(mid+,enn,next|);
Upnow(now,next);
return;
}
void Update(int sta,int enn,int now,int x,int y)
{
if(sta==enn&&sta==x)
{
segtr[now]=y;
nnow=now;
return;
}
int mid=dir(sta+enn,);
int next=mul(now,);
if(mid>=x)
Update(sta,mid,next,x,y);
else
Update(mid+,enn,next|,x,y);
Upnow(now,next);
return;
}
void Query(int sta,int enn,int now,int x,int y)//找到范围内大于y的最前面的值(基本可以看做最小值)
{
if(sta==enn)
{
ans=now;
flag=;
return;
}
int mid=dir(sta+enn,);
int next=mul(now,);
if(flag&&mid>=x&&segtr[next]>y)//这儿判断保证了的效率
Query(sta,mid,next,x,y);
if(flag&&segtr[next|]>y)
Query(mid+,enn,next|,x,y);
return;
}
int main()
{
int n,coun;
while(~scanf("%d",&n))
{
nnow=;
coun=;
mpos.clear();
mp.clear();
for(int i=;i<n;i++)
{
scanf("%s %d %d",str[i],&xx1[i],&yy1[i]);
if(str[i][] == 'a')
{
mp[make_pair(xx1[i],yy1[i])]=;//二维map
}
}
for(it=mp.begin();it!=mp.end();++it)
{
it->second=coun++;//二维map存应该是树上的第几个节点
if(!mpos.count(it->first.first))
mpos[it->first.first]=coun-;
}
coun--;
if(coun)//一定要注意count>0啊
Create(,coun,);
for(int i=;i<n;i++)
{
if(str[i][] == 'a')
{
Update(,coun,,mp[make_pair(xx1[i],yy1[i])],yy1[i]);
tem[nnow]=xx1[i];
}
else if(str[i][] == 'r')
{
Update(,coun,,mp[make_pair(xx1[i],yy1[i])],-);
tem[nnow]=xx1[i];
}
else
{
ans=-;
flag=;
iit=mpos.upper_bound(xx1[i]);
if(iit==mpos.end())
{
printf("-1\n");
continue;
}
Query(,coun,,iit->second,yy1[i]);
if(ans==-)
printf("-1\n");
else
printf("%d %d\n",tem[ans],segtr[ans]);
}
}
}
return ;
}

CodeForces 19D Points(线段树+map)的更多相关文章

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

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

  2. Codeforces Beta Round #19D(Points)线段树

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

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

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

  4. Codeforces 1140F Extending Set of Points 线段树 + 按秩合并并查集 (看题解)

    Extending Set of Points 我们能发现, 如果把x轴y轴看成点, 那么答案就是在各个连通块里面的x轴的个数乘以y轴的个数之和. 然后就变成了一个并查集的问题, 但是这个题目里面有撤 ...

  5. Codeforces 1140F Extending Set of Points (线段树分治+并查集)

    这题有以下几个步骤 1.离线处理出每个点的作用范围 2.根据线段树得出作用范围 3.根据分治把每个范围内的点记录和处理 #include<bits/stdc++.h> using name ...

  6. Codeforces 787D. Legacy 线段树建模+最短路

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

  7. Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)

    Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...

  8. Sereja and Brackets CodeForces - 380C (线段树+分治思路)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

  9. CodeForces 91B Queue (线段树,区间最值)

    http://codeforces.com/problemset/problem/91/B B. Queue time limit per test: 2 seconds memory limit p ...

随机推荐

  1. 9.nodejs权威指南--Socket.IO

    1. Socket.IO 1.1 服务器 var http = require('http'); var sio = require('socket.io'); var fs = require('f ...

  2. Java Thread.join()方法

    一.使用方式. join是Thread类的一个方法,启动线程后直接调用,例如: Thread t = new AThread(); t.start(); t.join(); 二.为什么要用join() ...

  3. Java for LeetCode 207 Course Schedule【Medium】

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  4. HTTP 错误 500.19- Internal Server Error 错误解决方法

    1.点击发布的文件夹,选择属性 2.选择安全,添加一个用户就可以了,设置为完全 --今天公司网页打开出现Server Error in '/' Application.怎么样解决. 解决方法:控制面板 ...

  5. ABAP 行列稳定刷新语句

    DATA stbl TYPE lvc_s_stbl. stbl-row = 'X'." 基于行的稳定刷新         stbl-col = 'X'." 基于列稳定刷新      ...

  6. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(七) 之 历史记录查询(时间,关键字,图片,文件),关键字高亮显示。

    前言 上一篇讲解了如何自定义右键菜单,都是前端的内容,本篇内容就一个:查询.聊天历史纪录查询,在之前介绍查找好友的那篇博客里已经提到过 Elasticsearch,今天它又要上场了.对于Elastic ...

  7. codevs 2851 菜菜买气球

    dp加二分法 链接:http://codevs.cn/problem/2851/ #include<iostream> #include<vector> #include< ...

  8. UVA 111 History Grading

    读题读了好久,其实就是在输入数据时要对数据的位置进行相应的改变 #include<iostream> #include<cstring> #include<cstdio& ...

  9. VCC、VDD、VSS、 VEE 和VPP的区别

    在电子电路中,常可以看到VCC.VDD和VSS三种不同的符号,它们有什么区别呢? 一.解释 VCC:C=circuit 表示电路的意思, 即接入电路的电压: VDD:D=device 表示器件的意思, ...

  10. 利用drozer进行Android渗透测试

    一.安装与启动 1. 安装 第一步:从 http://mwr.to/drozer 下载Drozer (Windows Installer) 第二步:在 Android 设备中安装 agent.apk ...