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. 如何把一篇Word文档里的所有换行符去掉?

    编辑-查找,查找框输入 ^13替换框不输入点击全部替换

  2. Linux运维常用的几个命令介绍【转】

    Linux运维常用的几个命令介绍 1. 查看系统内核版本​ [root@funsion geekxa]# cat /etc/issue CentOS release 6.5 (Final) Kerne ...

  3. CTSC 2017 游记

    惨啊,弱菜选手只报上了CTSC,去不了APIO. day -1 晚上的时候,坐上了去帝都的卧铺. 由于第二天就是luogu月赛round1,还得在火车上赶工出题... 颓了好长时间,把题面写出来了,用 ...

  4. javaScript-继承2种方式

    1.组合继承 组合继承带来的问题很明细就是父类的构造函数会调用两次,如: function Person(name, age, sex) { this.name = name; this.age = ...

  5. 做php网站后台开发,在Linux系统上进行更好吗?【转载】

    1. PHP是开源软件,它在bsd/linux/win下都有很好的正式版及孪生版.并非开发php就必须要在linux下进行.主机服务商们习惯性的把asp与php分为两个主机系列几进行销售.由于asp只 ...

  6. static变量和final变量

    1.static变量 按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或类变量:另一种是没有被static修饰的变量,叫实例变量.两者的区别是: 对于静态变量在内 ...

  7. POJ 3026 Borg Maze(Prim+bfs求各点间距离)

    题目链接:http://poj.org/problem?id=3026 题目大意:在一个y行 x列的迷宫中,有可行走的通路空格’  ‘,不可行走的墙’#’,还有两种英文字母A和S,现在从S出发,要求用 ...

  8. beego学习笔记(2)

    BEEGO的几个特点: 简单化 RESTful 支持.MVC 模型,可以使用 bee 工具快速地开发应用,包括监控代码修改进行热编译.自动化测试代码以及自动化打包部署. 智能化 支持智能路由.智能监控 ...

  9. C++的黑科技(深入探索C++对象模型)

    周二面了腾讯,之前只投了TST内推,貌似就是TST面试了 其中有一个问题,“如何产生一个不能被继承的类”,这道题我反反复复只想到,将父类的构造函数私有,让子类不能调用,最后归结出一个单例模式,但面试官 ...

  10. python中list的底层实现

    这里不讨论具体的实现细节,主要是转载这篇文章: 顺序表的原理与python中的list类型. 原文就不贴过来了,总结一下: 确定数据类型的意义在于确定一个数据在内存中占据的空间大小以及如何解释一段内存 ...