[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轴,条件是必需要经过这个 ...
随机推荐
- Windows下的包管理器Chocolatey
参考文档: https://www.jianshu.com/p/831aa4a280e7 https://www.jianshu.com/p/abaa0e8c261f
- linux shell学习三
Shell for循环 Shell for循环的语法如下所示 for 变量 in 列表 do command1 command2 ... commandN done 举例: ..} do echo $ ...
- CSS 颜色属性
一.十六进制表示,如: a{ color: #F0E68C; } 当RGB一样时,可以简写,如#AABBCC 可以写成 #ABC 二.rgb(r,g,b)形式,其中rgb的值为1~255之间,如: a ...
- gcc 随笔
将几个文件编译成一个动态库 libtest.so gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so 将test.c与动态库libte ...
- 【洛谷 P3648】 [APIO2014]序列分割 (斜率优化)
题目链接 假设有\(3\)段\(a,b,c\) 先切\(ab\)和先切\(bc\)的价值分别为 \(a(b+c)+bc=ab+bc+ac\) \((a+b)c+ab=ab+bc+ac\) 归纳一下可以 ...
- 2017 ACM暑期多校联合训练 - Team 4 1012 HDU 6078 Wavel Sequence (模拟)
题目链接 Problem Description Have you ever seen the wave? It's a wonderful view of nature. Little Q is a ...
- NYOJ 138 找球号(二) (哈希)
题目链接 描述 在某一国度里流行着一种游戏.游戏规则为:现有一堆球中,每个球上都有一个整数编号i(0<=i<=100000000),编号可重复,还有一个空箱子,现在有两种动作:一种是&qu ...
- java使用simpleDateFormat格式化日期 时间
时间日期标识符: yyyy:年 MM:月 dd:日 hh:1~12小时制(1-12) HH:24小时制(0-23) mm:分 ss:秒 S:毫秒 E:星期几 D:一年中的第几天 F:一月中的第几个星期 ...
- THINKPHP简单商品查询项目
代码:http://files.cnblogs.com/files/wordblog/test.zip
- struts的标签
<%@ taglib uri="/struts-tags" prefix="s"%> <%@ taglib uri="/WEB-IN ...