首页 技术 正文
技术 2022年11月19日
0 收藏 884 点赞 3,095 浏览 3340 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857