开始想不通,后来看网上说是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. MongoDB 分片的原理、搭建、应用

    一.概念: 分片(sharding)是指将数据库拆分,将其分散在不同的机器上的过程.将数据分散到不同的机器上,不需要功能强大的服务器就可以存储更多的数据和处理更大的负载.基本思想就是将集合切成小块,这 ...

  2. ada 图形编辑器 - GNAT GPL

    The GNAT GPL and SPARK GPL Editions are made available to the free software developers by AdaCore. T ...

  3. ffmpeg-20160527-git-bin

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  4. FFmpeg-20160422-snapshot-bin

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 F ...

  5. pgpool介绍和安装经验

    Pgpool的介绍 一.介绍 是一个工作在PostgreSQL多服务器和PostgreSQL数据库客户端之间的中间件. 二.概念图 三.功能 连接池:pgpool -Ⅱ保存 连 接到PostgreSQ ...

  6. hdu 1014.Uniform Generator 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目意思:给出 STEP 和 MOD,然后根据这个公式:seed(x+1) = [seed(x) ...

  7. 【leetcode】 Search a 2D Matrix (easy)

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  8. python基础——sorted()函数

    python基础——sorted()函数 排序算法 排序也是在程序中经常用到的算法.无论使用冒泡排序还是快速排序,排序的核心是比较两个元素的大小.如果是数字,我们可以直接比较,但如果是字符串或者两个d ...

  9. 警告 - no rule to process file 'WRP_CollectionView/README.md' of type net.daringfireball.markdown for architecture i386

    warning: no rule to process file '/Users/mac/Downloads/Demo/Self/WRP_CollectionView/WRP_CollectionVi ...

  10. Volley学习总结

    本文主要包括以下内容 volly基本操作(String与Json类型) volly图片操作 自定义volly volly源码分析 Volley简单易用,在性能方面也进行了大幅度的调整,它的设计目标就是 ...