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

Input
7
add 1 1
add 3 4
find 0 0
remove 1 1
find 0 0
add 1 1
find 0 0
Output
1 1
3 4
1 1
Input
13
add 5 5
add 5 6
add 5 7
add 6 5
add 6 6
add 6 7
add 7 5
add 7 6
add 7 7
find 6 6
remove 7 7
find 6 6
find 4 4
Output
7 7
-1
5 5 题解:
线段树维护
#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5 + ;
typedef pair < int ,int > dii;
struct operation
{
int x , y , tp ;
}op[maxn];
char str[];
int c,n,QueryY; vector < int > vi;
set < int > :: iterator it , it2; struct Segmenttree
{
typedef int SgTreeDataType;
struct treenode
{
int L , R ;
SgTreeDataType maxy;
set < int > s;
void updata(SgTreeDataType v){
s.insert(v);
maxy=max(maxy,v);
}
void remove(SgTreeDataType v){
s.erase(v);
if(s.empty()) maxy=;
else{
it=s.end();it--;
maxy=*it;
}
}
}; treenode tree[maxn * ]; inline void push_up(int o){
int lson = o << , rson = o << | ;
tree[o].maxy=max(tree[lson].maxy,tree[rson].maxy);
} void build(int L , int R , int o){
tree[o].L = L , tree[o].R = R,tree[o].maxy=;tree[o].s.empty();
if (R > L){
int mid = (L+R) >> ;
build(L,mid,o<<);
build(mid+,R,o<<|);
}
} void updata(int p,SgTreeDataType v,int o){
int L = tree[o].L , R = tree[o].R;
if (L==R) tree[o].updata(v);
else{
int mid = (L+R)>>;
if (p <= mid) updata(p,v,o<<);
else updata(p,v,o<<|);
push_up(o);
}
} void remove(int p,SgTreeDataType v,int o){
int L = tree[o].L , R = tree[o].R;
if (L==R) tree[o].remove(v);
else{
int mid = (L+R)>>;
if (p <= mid) remove(p,v,o<<);
else remove(p,v,o<<|);
push_up(o);
}
} dii query(int p,int o){
int L = tree[o].L , R = tree[o].R;
if (L>=p){
int lson = o << , rson = o << | ;
if(tree[o].maxy > QueryY){
if(L==R){
it = tree[o].s.upper_bound(QueryY);
return make_pair( L , *it);
}else{
if(tree[lson].maxy > QueryY) return query(p , lson);
else if(tree[rson].maxy > QueryY) return query(p , rson);
}
}else return make_pair(-,-);
}
else{
int mid = (L+R)>>;
dii res(-,-);
if (p <= mid) res = query(p,o<<);
if(~res.first) return res;
return query(p,o<<|);
}
}
}Sgtree; inline int GetRank(int x){
return lower_bound( vi.begin() , vi.begin() + c , x ) - vi.begin();
} int main(int argc,char *argv[]){
scanf("%d",&n);
for(int i = ; i <= n ; ++ i){
int x , y;
scanf("%s%d%d",str,&op[i].x,&op[i].y);
if(str[]=='a') op[i].tp = ;
else if(str[]=='r') op[i].tp = ;
else op[i].tp = ;
vi.push_back(op[i].x);
}
sort( vi.begin() , vi.end() );
c = unique( vi.begin() , vi.end() ) - vi.begin();
Sgtree.build( , c - , );
for(int i = ; i <= n ; ++ i){
op[i].x = GetRank( op[i].x );
if(op[i].tp==) Sgtree.updata(op[i].x,op[i].y,);
else if(op[i].tp==) Sgtree.remove(op[i].x,op[i].y,);
else{
if(op[i].x == c - ){
printf("-1\n");
continue;
}
QueryY = op[i].y;
dii ans = Sgtree.query(op[i].x + , );
if(ans.first==-) printf("-1\n");
else printf("%d %d\n",vi[ans.first],ans.second);
}
}
return ;
}

CodeForces 19D Points的更多相关文章

  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 19D Points(离散化+线段树+单点更新)

    题目链接: huangjing 题意:给了三种操作 1:add(x,y)将这个点增加二维坐标系 2:remove(x,y)将这个点从二维坐标系移除. 3:find(x,y)就是找到在(x,y)右上方的 ...

  3. CodeForces 19D Points(线段树+map)

    开始想不通,后来看网上说是set,就有一个想法是对每个x建一个set...然后又想直接建立两重的set就好,最后发现不行,自己想多了...  题意是给你三种操作:add (x y) 平面添加(x y) ...

  4. codeforces 19D D. Points 树套树

    D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...

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

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

  6. codeforces 872E. Points, Lines and Ready-made Titles

    http://codeforces.com/contest/872/problem/E E. Points, Lines and Ready-made Titles time limit per te ...

  7. codeforces 251A Points on Line(二分or单调队列)

    Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...

  8. CodeForces 577E Points on Plane(莫队思维题)

    题目描述 On a plane are nn points ( x_{i}xi​ , y_{i}yi​ ) with integer coordinates between 00 and 10^{6} ...

  9. 『ACM C++』 Codeforces | 1066A - Points in Segments

    大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...

随机推荐

  1. 有关autoresizingMask属性遇到的一个小问题

    前言:在讲述这个小问题之前,我们有必要先了解一下UIViewAutoresizing的有关属性概念和使用详解. 参考:自动布局之autoresizingMask使用详解(Storyboard& ...

  2. thinkphp+datatables+ajax 大量数据服务器端查询

    今天一白天全耗在这个问题上了,知乎2小时除外... 现在19:28分,记下来以备后查. 问题描述:从后台数据库查询人员信息,1w多条,使用一个好看的基于bootstrap的模板 Bootstrap-A ...

  3. appium新版本不支持findElementByName,切换到findElementByAndroidUIAutomator

    appium 1.7.6 不支持findElementByName(locator)  不知道为什么? 脚本中许多这样的语句,麻烦事情多了 org.openqa.selenium.InvalidSel ...

  4. iOS UITableView 修改滚动条颜色 默认选中第一条

    //隐藏 self.tableView.showsVerticalScrollIndicator = NO; //修改颜色 self.tableView.indicatorStyle=UIScroll ...

  5. 关于使用百度ueditor时的一些问题

    本来这些问题直接在百度贴吧里回答不就完事了,可是好死不死的,百度贴吧里老出现 未知错误,错误号:230274 看来还是算了,自己做一个随笔记录一下好了 关于我们获取里面的内容时,老是会有一个<p ...

  6. iTunes备份文件路径

    Windows 7 电脑:C:\Users\使用者名称\AppData\Roaming\Apple Computer\MobileSync\Backup XP 电脑:C:\Documents and ...

  7. lesson5:利用jmeter来压测消息队列(activemq)

    本文讲述了利用jmeter来压测消息队列,其中消息队列采用apache的activemq,jmeter本身是支持符合jms标准消息队列的压测,由于jmeter的官方sampler配置比较复杂,本文直接 ...

  8. android2.3 View视图框架源码分析之一:android是如何创建一个view的?

    View是所有控件的一个基类,无论是布局(Layout),还是控件(Widget)都是继承自View类.只不过layout是一个特殊的view,它里面创建一个view的数组可以包含其他的view而已. ...

  9. linux命令帮助

    Linux命令格式:command [options] [arguments]command:命令options: 参数 [] 表示是可选的;<> 表示是可变化的; x|y|z 表示只能选 ...

  10. apache ab工具对网站进行压力测试

    Apache -- ab工具主要测试网站的(并发性能) 这个工具非常的强大. 基本语法 :   cmd>ab.exe –n 请求总次数  -c 并发数 请求页面的url     进入到ab.ex ...