[Codeforces19D]Points 线段树
大致题意:
给出n个询问,每次询问有三种:
1、往平面上加一个点
2、删除平面上的一个点
3、给出一个点p,查询平面上某点q,使得q.x>p.x且q.y>p.y,输出x轴坐标最小的q,若有多个,输出y最小的
点的坐标较大,需要先离散点坐标,线段树维护x坐标对应的最大的y坐标,
查询用线段树定位x坐标,用set数组查询y坐标即可,因为总共只会用2e5个点,不会超内存
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 200100
#define eps 1e-7
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e9+9
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
struct Point {
int x,y;
int mk,id;
bool operator < (const Point &a)const{
if(x==a.x) return y<a.y;
return x<a.x;
}
bool operator == (const Point &a)const{
return x==a.x && y==a.y;
}
void read(int idd,int mkk) {
scanf("%d%d",&x,&y);
id=idd;mk=mkk;
}
};
bool cmp(Point a,Point b){
return a.id<b.id;
}
Point ad[MAXN];
int add[MAXN];
int t[MAXN<<];
set<int>mp[MAXN];
set<int>::iterator it;
void up(int rt){
t[rt]=max(t[rt<<],t[rt<<|]);
}
void Change(int x,int l,int r,int rt){
if(l==r && r==x){
if(mp[x].size()==){
t[rt]=;
return ;
}
t[rt]=(*mp[x].rbegin());
return ;
}
int mid=l+r>>;
if(x<=mid) Change(x,lson);
else Change(x,rson);
up(rt);
}
int Query(int x,int xx,int l,int r,int rt){
int mid=l+r>>;
if(l>=xx) {
if(t[rt]>x){
if(l==r) return l;
else {
if(t[rt<<]>x) return Query(x,xx,lson);
else if(t[rt<<|]>x) return Query(x,xx,rson);
}
}else return inf; }else{
int res=inf;
if(xx<=mid) res=Query(x,xx,lson);
if(res!=inf) return res;
return Query(x,xx,rson);
}
}
int n,cnt;
char s[];
void solve(){
scanf("%d",&n);
cnt=;
For(i,,n){
scanf("%s",s);
if(s[]=='a') ad[i].read(i,);
else if(s[]=='r') ad[i].read(i,);
else ad[i].read(i,);
add[i]=ad[i].x;
}
cnt=n;
sort(add+,add+n+);
cnt=unique(add+,add++cnt)-(add+);
For(i,,n){
int idx=upper_bound(add+,add++cnt,ad[i].x)-(add+);
if(ad[i].mk==) {
mp[idx].insert(ad[i].y);
Change(idx,,cnt,);
}
else if(ad[i].mk==) {
mp[idx].erase(ad[i].y);
Change(idx,,cnt,);
}
else {
int ans=Query(ad[i].y,idx+,,cnt,);
if(ans==inf) {puts("-1");continue;}
it=mp[ans].upper_bound(ad[i].y);
if(it==mp[ans].end()) {puts("-1");continue;}
printf("%d %d\n",add[ans],(*it));
}
}
}
int main(){
// fre("in.txt","r",stdin);
int t=;
solve();
return ;
}
[Codeforces19D]Points 线段树的更多相关文章
- Codeforces 1140F Extending Set of Points 线段树 + 按秩合并并查集 (看题解)
Extending Set of Points 我们能发现, 如果把x轴y轴看成点, 那么答案就是在各个连通块里面的x轴的个数乘以y轴的个数之和. 然后就变成了一个并查集的问题, 但是这个题目里面有撤 ...
- CodeForces 19D Points (线段树+set)
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- [hdu4347]The Closest M Points(线段树形式kd-tree)
解题关键:kdtree模板题,距离某点最近的m个点. #include<cstdio> #include<cstring> #include<algorithm> ...
- Codeforces Beta Round #19D(Points)线段树
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- CF 19D - Points 线段树套平衡树
题目在这: 给出三种操作: 1.增加点(x,y) 2.删除点(x,y) 3.询问在点(x,y)右上方的点,如果有相同,输出最左边的,如果还有相同,输出最低的那个点 分析: 线段树套平衡树. 我们先离散 ...
- Codeforces 1140F Extending Set of Points (线段树分治+并查集)
这题有以下几个步骤 1.离线处理出每个点的作用范围 2.根据线段树得出作用范围 3.根据分治把每个范围内的点记录和处理 #include<bits/stdc++.h> using name ...
- Codeforces 295E Yaroslav and Points 线段树
Yaroslav and Points 明明区间合并一下就好的东西, 为什么我会写得这么麻烦的方法啊啊啊. #include<bits/stdc++.h> #define LL long ...
- CodeForces19D:Points(线段树+set(动态查找每个点右上方的点))
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coo ...
- UVA10869 - Brownie Points II(线段树)
UVA10869 - Brownie Points II(线段树) 题目链接 题目大意:平面上有n个点,Stan和Ollie在玩游戏,游戏规则是:Stan先画一条竖直的线作为y轴,条件是必需要经过这个 ...
随机推荐
- (转)IO复用,AIO,BIO,NIO,同步,异步,阻塞和非阻塞 区别
本文来自:https://www.cnblogs.com/aspirant/p/6877350.html?utm_source=itdadao&utm_medium=referral,非常感谢 ...
- 全国排名的问题(linq 的连表查询 等同于sql的left join)
前言:要获得全国排名,(因为权限问题,显示的数据不是全国的数据,而是某个分区的数据,因此,不能获得数据后排序得到排名) 显示本部的员工积分并且获得在全国的排名. 我的思路:获得显示的员工信息集合1,获 ...
- conda 虚拟环境
一.jupyter notbook (1)需要安装: conda install ipykernel (2)首先激活对应的conda环境 source activate 环境名称 (3)将环境写入no ...
- 学大伟业 2017 国庆 Day1
期望得分:100+100+20=220 实际得分:100+100+20=220 (好久没有期望==实际了 ,~\(≧▽≦)/~) 对于 a........a 如果 第1个a 后面出现的第1个b~z 是 ...
- NOIP2013 提高组 Day2
期望得分:100+100+30+=230+ 实际得分:100+70+30=200 T2 觉得题目描述有歧义: 若存在2i却不存在2i+1,自己按不合法做的,实际是合法的 T3 bfs 难以估分 虽然 ...
- 【BZOJ4565】【HAOI2016】字符合并 [状压DP][区间DP]
字符合并 Time Limit: 20 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 有一个长度为 n 的 01 串,你 ...
- NYOJ 231 Apple Tree (树状数组)
题目链接 描述 There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in t ...
- 常用的css3新特性总结
1:CSS3阴影 box-shadow的使用和技巧总结: 基本语法是{box-shadow:[inset] x-offset y-offset blur-radius spread-radiuscol ...
- C# 操作资源文件
(1)首先引用这两个命名空间 (2)两种方式调用资源文件中的内容 private void button2_Click(object sender, EventArgs e) { //通过Resour ...
- koa通过get请求获取参数
1.通过get方式请求获取参数的方式有两种 通过上下文获取 通过request获取 获得的格式有两种:query与querystring 注意:querystring为小写,驼峰格式会导致无法获取 2 ...