codeforces 19D D. Points 树套树
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
Sample Input
add 1 1
add 3 4
find 0 0
remove 1 1
find 0 0
add 1 1
find 0 0
Sample Output
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 树套树的更多相关文章
- Codeforces 1422F - Boring Queries(树套树)
upd on 2021.9.5:昨天的那个版本被 2-tower 卡爆了,故今天重发一个. Codeforces 题面传送门 & 洛谷题面传送门 没往"每个数最多只有一个 \(> ...
- 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了这道题,但是感觉就算比赛再次遇到类似 ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- 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 ...
- bzoj3262: 陌上花开(树套树)
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- bzoj3295: [Cqoi2011]动态逆序对(树套树)
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- BZOJ 3110 k大数查询 & 树套树
题意: 有n个位置,每个位置可以看做一个集合,现在要求你实现一个数据结构支持以下功能: 1:在a-b的集合中插入一个数 2:询问a-b集合中所有元素的第k大. SOL: 调得火大! 李建说数据结构题能 ...
- BZOJ 3110 树套树 && 永久化标记
感觉树套树是个非常高深的数据结构.从来没写过 #include <iostream> #include <cstdio> #include <algorithm> ...
- 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树套树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 这题调了我相当长的时间,1wa1a,我是第一次写树套树,这个是树状数组套splay,在每个区间 ...
- hdu 4417 Super Mario/树套树
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意很简单,给定一个序列求一个区间 [L, R,]中小于等于H的元素的个数. 好像函数式线段树可 ...
随机推荐
- Java Spring boot 企业微信点餐系统
欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字" springboot "免费领取(一个有温度的微信公众号,期待与你共同进步~~~坚持原创,分享美 ...
- ios测试apk
最近apk在ios上面测试总是会遇到奇奇怪怪的问题,现在是两个项目要集成在一个apk中所以将两个项目运行之后都是编译成了.a文件,然后在两个.a文件中都设置了两个意义相同变量名相同的全局变量(标识当前 ...
- Java学习笔记()ArrayList
1.什么是ArrayList ArrayList就是传说中的动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了如下一些好处: 动态的增加和减少元素 实现了ICollection和ILis ...
- GUC-4 CopyOnWriteArrayList/CopyOnWriteArraySet
/* * CopyOnWriteArrayList/CopyOnWriteArraySet : “写入并复制” * 注意:添加操作多时,效率低,因为每次添加时都会进行复制,开销非常的大.并发迭代操作多 ...
- PHP 文件夹操作「复制、删除、查看大小、重命名」递归实现
PHP虽然提供了 filesize.copy.unlink 等文件操作的函数,但是没有提供 dirsize.copydir.rmdirs 等文件夹操作的函数(rmdir也只能删除空目录).所以只能手动 ...
- 环状序列(UVa1584)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...
- day3修改配置文件
有如下配置文件,在指定文件位置添加一条新的记录: global log 127.0.0.1 local2 daemon maxconn log 127.0.0.1 local2 info defaul ...
- Python的hasattr() getattr() setattr() 函数使用方法(简介)
hasattr(object, name)判断一个对象里面是否有name属性或者name方法,返回BOOL值,有name特性返回True, 否则返回False.需要注意的是name要用括号括起来 1 ...
- CodeForces 785D Anton and School - 2
枚举,容斥原理,范德蒙恒等式. 先预处理每个位置之前有多少个左括号,记为$L[i]$. 每个位置之后有多少个右括号,记为$R[i]$. 然后枚举子序列中第一个右括号的位置,计算这个括号的第一个右括号的 ...
- Am335x u-boot 代码大概流程
在_面之前的流程和u-boot-spl一样,区别在于_main中. 对于u-boot 2016.03来说 ENTRY(_main) /* * Set up initial C runtime envi ...