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. [MySQL] AUTO_INCREMENT lock Handing in InnoDB

    MySQL AUTO_INCREMENT lock Handing in InnoDB 在MySQL的表设计中很普遍的使用自增长字段作为表主键, 实际生产中我们也是这样约束业务开发同学的, 其中的优势 ...

  2. HttpURLConnection传json

    private static String sendToWangTing(DataRow dataRow) throws IOException{ String ip = Configuration. ...

  3. 设置Git远程仓库

    1,注册一个GitHub账户,登陆GitHub账户,添加一个储存库 2,进入Ubuntu命令窗口,创建文件夹.如   mkdir   git echo "# first_git" ...

  4. angular项目文件概览

    在Mac上打开终端,输入ng new b-app  如下: 然后在webstorm中打开 src文件夹 你的应用代码位于src文件夹中. 所有的Angular组件.模板.样式.图片以及你的应用所需的任 ...

  5. C#串口serialPort操作

    现在大多数硬件设备均采用串口技术与计算机相连,因此串口的应用程序开发越来越普遍.例如,在计算机没有安装网卡的情况下,将本机上的一些信息数据 传输到另一台计算机上,那么利用串口通信就可以实现.运行本程序 ...

  6. Spring mvc知识点总结——面试篇

    一.MVC思想MVC(Model-View-Controller)三元组的概念:1.Model(模型):数据模型,提供要展示的数据,因此包含数据和行为,可以认为是领域模型或JavaBean组件(包含数 ...

  7. ajax刷新输出实时数据

    setInterval('shuaxin()',3000); function shuaxin(){ $.ajax({//股票 url:"http://apimarkets.wallstre ...

  8. LeetCode862. Shortest Subarray with Sum at Least K

    Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...

  9. css写无缝滚动

    html结构: <div class="authority"> <ul> <li> <img src="./images/rep ...

  10. 【笔试题】怎样将 GB2312 编码的字符串转换为 ISO-8859-1 编码的字符串?

    笔试题 怎样将 GB2312 编码的字符串转换为 ISO-8859-1 编码的字符串? import java.io.UnsupportedEncodingException; public clas ...