time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
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 <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define llt long long int
#define ml(x, y) ((x + y) >> 1)
#define mr(x, y) (((x + y) >> 1) + 1)
#define pl(p) (p << 1)
#define pr(p) ((p << 1) | 1)
#define N 200005
using namespace std;
map<int, int> mp;//离散化使用
vector<int> tx;//额外记录x
int segtree[N << ];//维护该区间的最大值,查询用
set<int> ty[N];//存对应x的所有y值
struct node
{
int x, y;
char op[];
}point[N];
void build(int l, int r, int p)//初始化线段树
{
segtree[p] = ;
if (l < r)
{
build(l, ml(l, r), pl(p));
build(mr(l, r), r, pr(p));
}
else
ty[l].clear();
}
void update(int l, int r, int p, int x, int y, int tag)
{
if (l == r)
{
if (tag)//add操作
{
ty[l].insert(y);
if (segtree[p] < y)
segtree[p] = y;
}
else
{
ty[l].erase(y);
segtree[p] = ty[l].empty() ? : *(--ty[l].end());
}
return;
}
if (ml(l, r) >= x)
update(l, ml(l, r), pl(p), x, y, tag);
else
update(mr(l, r), r, pr(p), x, y, tag);
segtree[p] = max(segtree[pl(p)], segtree[pr(p)]);
}
pair<int, int> query(int l, int r, int p, int x, int y)
{
if (r < x || segtree[p] < y)//未找到
return make_pair(-, -);
if (r == l)//找到了最合适的
return make_pair(r, *ty[r].lower_bound(y));
pair<int, int> ans = query(l, ml(l, r), pl(p), x, y);//先往左找
if (ans.first != -)//找到了
return ans;
return query(mr(l, r), r, pr(p), x, y);//未找到,右边找
}
int main()
{
int n, i, size;
while (~scanf("%d", &n))
{
tx.clear();
mp.clear();
for (i = ; i < n; i++)
{
scanf("%s%d%d", point[i].op, &point[i].x, &point[i].y);
tx.push_back(point[i].x);
}
sort(tx.begin(), tx.end());//排序
tx.erase(unique(tx.begin(), tx.end()), tx.end());//除去相同的元素
size = tx.size() - ;
build(, size, );
for (i = ; i <= size; i++)//进行离散化
mp[tx[i]] = i;
for (i = ; i < n; i++)
{
if (point[i].op[] == 'f')
{
pair<int, int> ans = query(, size, , mp[point[i].x] + , point[i].y + );
if (ans.first >= )
printf("%d %d\n", tx[ans.first], ans.second);
else
puts("-1");
continue;
}
update(, size, , mp[point[i].x], point[i].y, point[i].op[] == 'a'? : );
}
}
return ;
}

Codeforces Beta Round #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. CF 19D - Points 线段树套平衡树

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

  3. Codeforces 295E Yaroslav and Points 线段树

    Yaroslav and Points 明明区间合并一下就好的东西, 为什么我会写得这么麻烦的方法啊啊啊. #include<bits/stdc++.h> #define LL long ...

  4. Palisection(Codeforces Beta Round #17E+回文树)

    题目链接 传送门 题意 给你一个串串,问你有多少对回文串相交. 思路 由于正着做不太好算答案,那么我们考虑用总的回文对数减去不相交的回文对数. 而不相交的回文对数可以通过计算以\(i\)为右端点的回文 ...

  5. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  6. Codeforces Beta Round #35 (Div. 2)

    Codeforces Beta Round #35 (Div. 2) http://codeforces.com/contest/35 A 这场的输入输出是到文件中的,不是标准的输入输出...没注意看 ...

  7. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. bzoj 1880: [Sdoi2009]Elaxia的路线【spfa+拓扑排序】

    有趣啊 先spfa分别求出以s1,t1,s2,t2为起点的最短路,然后把在s1-->t1或者s2-->t2最短路上的边重新建有向图,跑拓扑最长路即可 #include<iostrea ...

  2. bzoj 3875: [Ahoi2014&Jsoi2014]骑士游戏【dp+spfa】

    设f[i]为杀死i的最小代价,显然\( f[i]=min(k[i],s[i]+\sum f[to]) \) 但是这个东西有后效性,所以我们使用spfa来做,具体就是每更新一个f[i],就把能被它更新的 ...

  3. 洛谷 P4014 分配问题 【最小费用最大流+最大费用最大流】

    其实KM更快--但是这道题不卡,所以用了简单粗暴的费用流,建图非常简单,s向所有人连流量为1费用为0的边来限制流量,所有工作向t连流量为1费用为0的边,然后对应的人和工作连(i,j,1,cij),跑一 ...

  4. P3308 [SDOI2014]LIS(最小割+退流)

    传送门 设\(f[i]\)为以\(i\)结尾的最长上升子序列.可以考虑建这样一张图,对于所有的\(i<j,f[j]=f[i+1]\)连边\((i,j)\),\(f[i]=1\)的话连边\((S, ...

  5. Ocelot(六)- 架构图

    简介 Ocelot是一个用.NET Core实现并且开源的API网关,它功能强大,包括了:路由.请求聚合.服务发现.认证.鉴权.限流熔断.并内置了负载均衡器与Service Fabric.Butter ...

  6. 解决window.opener.obj instanceof Object会输出false的问题

    在a.html页面中: window.obj = {name: "jinbang"} 在a.html页面中打开新窗口b.html页面: console.log(window.ope ...

  7. 乐搏讲自动化测试-Python适用公司类型(6)

    相信小伙伴们都知道,随着软件测试行业的发展和进步自动化测试已经成为必然.在竞争日益激烈的市场环境中也是你升职加薪的利器. 所以,小编决定从今天起!将要系统.连续.高质量的持续更新「整套自动化测试」文章 ...

  8. Qt之程序发布以及打包成exe安装包

    一.简述 Qt项目开发完成之后,需要打包发布程序,而因为用户电脑上没有Qt配置环境,所以需要将release生成的exe文件和所依赖的dll文件复制到一个文件夹中,然后再用 Inno Setup打包工 ...

  9. 二分+树状数组/线段树(区间更新) HDOJ 4339 Query

    题目传送门 题意:给两串字符串,操作1:替换其中一个字符串的某个位置的字符 操作2:查询从p开始相等的最长连续长度 分析:树状数组可以维护一个区间内公共长度(连续)的情况,查询时用二分查找最远的端点即 ...

  10. 199 Binary Tree Right Side View 二叉树的右视图

    给定一棵二叉树,想象自己站在它的右侧,返回从顶部到底部看到的节点值.例如:给定以下二叉树,   1            <--- /   \2     3         <--- \  ...