[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轴,条件是必需要经过这个 ...
随机推荐
- 简单实现VUE的双向数据绑定
<!DOCTYPE html> <html> <head> <title>vue-双向数据绑定的简单实现</title> </head ...
- dp+分类讨论 Gym 101128E
题目链接:http://codeforces.com/gym/101128 感觉这个人写的不错的(我只看了题目大意):http://blog.csdn.net/v5zsq/article/detail ...
- HDU 2608 底数优化分块 暴力
T(n) as the sum of all numbers which are positive integers can divied n. and S(n) = T(1) + T(2) + T( ...
- PHP扩展开发--01.编写一个helloWorld扩展
为什么要用C扩展 C是静态编译的,执行效率比PHP代码高很多.同样的运算代码,使用C来开发,性能会比PHP要提升数百倍. 另外C扩展是在进程启动时加载的,PHP代码只能操作Request生命周期的数据 ...
- aidl.exe'' finished with non-zero exit value 1问题解决【转载】
PS:Android Studio用AIDL时,碰到一个非常棘手的问题,但是百度之,压根非法解决,FQ出去,终于找到了一篇解决问题的文章,特地转载之. 之前使用aidl传递的都是基本的数据类型比如in ...
- DOM操作二三事
我突然想起了append(),但是我记不太清它是原生JS的还是jQuery封装的,貌似是JS的,咦?那它在jQuery里叫什么来着?哎呀!记不清了!确定append()是JS里的?不是jQuery里的 ...
- java中error和exception
异常是指程序运行时发生的错误. Throwable是所有异常的父类,它有两个子类:Error和Exception. 1.Error表示程序在运行期间发生了非常严重的错误,并且该错误是不可恢复的.Err ...
- [php排错] Forbidden You don't have permission to access / on this server.
刚开始接触PHP,在搭建完环境后发现输入127.0.0.1可以访问界面,但是输入http://localhost却提醒无权访问,在百度之后发现是php中的httpd.conf的作用 在wamp中搜索发 ...
- 手机网页的头部meta的相关配置~~
今天使用sublime写手机端网页的时候,发现木有meta的自动生成手机网页的快捷键·~ 然后就去网上巴拉,准备存储一份~~哈哈 一.天猫 <title>天猫触屏版</title&g ...
- King's Quest POJ - 1904 匈牙利算法的思想+tarjan缩点+染色
题目链接:https://cn.vjudge.net/problem/POJ-1904 自己一开始的想法,打算用匈牙利算法实现,找二分图的最大匹配.但是打了打发现,不太好实现.原因如下:匈牙利算法是不 ...