D. Points

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

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

Description

Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0, 0) is located in the bottom-left corner, Ox axis is directed right, Oy axis is directed up. Pete gives Bob requests of three types:

  • add x y — on the sheet of paper Bob marks a point with coordinates (x, y). For each request of this type it's guaranteed that point (x, y) is not yet marked on Bob's sheet at the time of the request.
  • remove x y — on the sheet of paper Bob erases the previously marked point with coordinates (x, y). For each request of this type it's guaranteed that point (x, y) is already marked on Bob's sheet at the time of the request.
  • find x y — on the sheet of paper Bob finds all the marked points, lying strictly above and strictly to the right of point (x, y). Among these points Bob chooses the leftmost one, if it is not unique, he chooses the bottommost one, and gives its coordinates to Pete.

Bob managed to answer the requests, when they were 10, 100 or 1000, but when their amount grew up to 2·105, Bob failed to cope. Now he needs a program that will answer all Pete's requests. Help Bob, please!

Input

The first input line contains number n (1 ≤ n ≤ 2·105) — amount of requests. Then there follow n lines — descriptions of the requests. add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input file are non-negative and don't exceed 109.

Output

For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (x, y). If there are no points strictly above and to the right of point (x, y), output -1.
 

Sample Input

7

add 1 1

add 3 4

find 0 0

remove 1 1

find 0 0

add 1 1

find 0 0

Sample Output

1 1

3 4

1 1

HINT

题意

二维插入删除,找右上角的点

题解:

线段树套set

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define LL(x) (x<<1)
#define RR(x) (x<<1|1)
const int N=2e5+; vector<int> sx;
map<int,int> imap; struct OP
{
char str[];
int x,y;
void input()
{
scanf("%s%d%d",str,&x,&y);
sx.push_back(x);
}
}op[N];
struct Segtree
{
int imax[N*];
set<int> valu[N];
void clear()
{
memset(imax,-,sizeof(imax));
for(int i=;i<N;i++) valu[i].clear();
}
void add(int st,int ed,int ind,int x,int y)
{
imax[ind]=max(imax[ind],y);
if(st==ed) valu[x].insert(y);//注意这里是x
else
{
int mid=st+(ed-st)/;
if(x<=mid) add(st,mid,LL(ind),x,y);
else add(mid+,ed,RR(ind),x,y);
}
}
void remove(int st,int ed,int ind,int x,int y)
{
if(st==ed)
{
valu[x].erase(y);
imax[ind]=valu[x].empty()?-:*(--valu[x].end());
}
else
{
int mid=st+(ed-st)/;
if(x<=mid) remove(st,mid,LL(ind),x,y);
else remove(mid+,ed,RR(ind),x,y);
imax[ind]=max(imax[LL(ind)],imax[RR(ind)]);
}
}
pair<int,int> find(int st,int ed,int ind,int x,int y)
{
if(imax[ind]<y||ed<x) return make_pair(-,-);
if(st==ed) return make_pair(st,*(valu[st].lower_bound(y)));
else
{
int mid=st+(ed-st)/;
pair<int,int> tmp=find(st,mid,LL(ind),x,y);
if(tmp.first!=-) return tmp;
return find(mid+,ed,RR(ind),x,y);
}
}
}seg;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
sx.clear();imap.clear();seg.clear();
for(int i=;i<n;i++) op[i].input(); sort(sx.begin(),sx.end());
sx.erase(unique(sx.begin(),sx.end()),sx.end());
int len=(int)sx.size()-;
for(int i=;i<=len;i++) imap[sx[i]]=i; for(int i=;i<n;i++)
{
char ch=op[i].str[];
int x=op[i].x,y=op[i].y;
if(ch=='a') seg.add(,len,,imap[x],y);
else if(ch=='r') seg.remove(,len,,imap[x],y);
else
{
pair<int,int> res=seg.find(,len,,imap[x]+,y+);
if(res.first==-) puts("-1");
else printf("%d %d\n",sx[res.first],res.second);
}
}
}
return ;
}

codeforces 19D D. Points 树套树的更多相关文章

  1. Codeforces 1422F - Boring Queries(树套树)

    upd on 2021.9.5:昨天的那个版本被 2-tower 卡爆了,故今天重发一个. Codeforces 题面传送门 & 洛谷题面传送门 没往"每个数最多只有一个 \(> ...

  2. Educational Codeforces Round 56 (Rated for Div. 2) E(1093E) Intersection of Permutations (树套树,pb_ds)

    题意和分析在之前的链接中有:https://www.cnblogs.com/pkgunboat/p/10160741.html 之前补题用三维偏序的cdq的分治A了这道题,但是感觉就算比赛再次遇到类似 ...

  3. BZOJ 3110: [Zjoi2013]K大数查询 [树套树]

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6050  Solved: 2007[Submit][Sta ...

  4. BZOJ4170 极光(CDQ分治 或 树套树)

    传送门 BZOJ上的题目没有题面-- [样例输入] 3 5 2 4 3 Query 2 2 Modify 1 3 Query 2 2 Modify 1 2 Query 1 1 [样例输出] 2 3 3 ...

  5. bzoj3262: 陌上花开(树套树)

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  6. bzoj3295: [Cqoi2011]动态逆序对(树套树)

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  7. BZOJ 3110 k大数查询 & 树套树

    题意: 有n个位置,每个位置可以看做一个集合,现在要求你实现一个数据结构支持以下功能: 1:在a-b的集合中插入一个数 2:询问a-b集合中所有元素的第k大. SOL: 调得火大! 李建说数据结构题能 ...

  8. BZOJ 3110 树套树 && 永久化标记

    感觉树套树是个非常高深的数据结构.从来没写过 #include <iostream> #include <cstdio> #include <algorithm> ...

  9. 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树套树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1901 这题调了我相当长的时间,1wa1a,我是第一次写树套树,这个是树状数组套splay,在每个区间 ...

  10. hdu 4417 Super Mario/树套树

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意很简单,给定一个序列求一个区间 [L, R,]中小于等于H的元素的个数. 好像函数式线段树可 ...

随机推荐

  1. 日常开发技巧:x11-forward,使用远程机器的gui程序

    背景 日常用过ssh登录服务器进行工作,尽管大部分时间,都只需要终端操作,编辑源码也是vim就够用了. 但有时候,还是需要使用gui程序的,比如打开一份pdf,word,ppt,excel等. 碰到这 ...

  2. ps aux排序

    按内存升序排列: ps aux --sort=+rss 按内存降序排列: ps aux --sort=-rss 按cpu升序排列: ps aux --sort=+%cpu 为按cpu降序排列. ps ...

  3. 【技术分享】ReBreakCaptcha:利用谷歌来破解谷歌的验证码

    概述 从2016年开始,我就在琢磨寻找一种新的绕过谷歌验证码v2的方法会有多难,如果这种方法能够适用于任何环境而不仅仅是针对特定的案例,那这种方法将是非常理想的.接下来我将向你介绍ReBreakCap ...

  4. 通过复制(拷贝)新建javaweb项目报错无法访问

    我们有时候为了方便,用eclipse在原来动态web项目上直接复制,粘贴项目,来形成以一个新的项目.可是运行的时候,它显示的url地址,还是原来的项目地址.初步判定,有可能是eclipse配置的问题. ...

  5. CSS背景横向平铺BUG,解决方法

    给定DIV一个背景图片横向平铺,缩小浏览器,拉动横向滚动条,此时触发此BUG:背景图片平铺不完整 解决办法: 1.把背景图片写在BODY上,此办法局限于没有使用iframe的情况下,所以少用 2.设定 ...

  6. js获取系统时间

    //------------------------------------获取系统日期时间 var oDate=new Date(); //alert(oDate.getFullYear());// ...

  7. curd 插件

    1. Django项目启动 自动加载文件 制作启动文件 . 注册strak 在apps.py 类里面增加如下 def ready(self): from django.utils.module_loa ...

  8. 以太坊go-ethereum项目源码本地环境搭建

    如果要深入了解go-ethereum项目的实现与机制,看源代码是必不可少的.今天这篇博客就简单介绍一下如何在本地搭建项目的开发环境. GO语言环境搭建 以win8为例,访问地址https://gola ...

  9. STL中stack/queue/map以及Boost unordered_map 的使用方法

    一.stackstack 模板类的定义在<stack>头文件中.stack 模板类需要两个模板参数,一个是元素类型,一个容器类型,但只有元素类型是必要的,在不指定容器类型时,默认的容器类型 ...

  10. 纯js的N级联动列表框 —— 基于jQuery

    多个列表框联动,不算是啥大问题,但是却挺麻烦,那么怎么才能够尽量方便一点呢?网上搜了一下,没发现太好用的,于是就自己写了一个.基于jQuery,无限级联动,支持下拉列表框和列表框. 先说一下步骤和使用 ...