[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轴,条件是必需要经过这个 ...
随机推荐
- (转)MySQL建表设置两个默认CURRENT_TIMESTAMP的技巧
业务场景: 例如用户表,我们需要建一个字段是创建时间, 一个字段是更新时间. 解决办法可以是指定插入时间,也可以使用数据库的默认时间. 在mysql中如果设置两个默认CURRENT_TIMESTAMP ...
- LeetCode-Insertion Sort List[AC源码]
package com.lw.leet5; /** * @ClassName:Solution * @Description: * Insertion Sort List * Sort a linke ...
- Daily Report-1126
今日: 上午主要是回顾了react,阅读官方文档的时候发现了list中key值设计的必要性. 看了部分react源码,发现有些吃力,在询问羽牧学长之后调整策略,从redux和mobx入手,先多熟悉用法 ...
- c语言学习笔记.数组.
数组: 可以存储一个固定大小的相同类型元素的顺序集合,比如int类型的数组.float类型的数组,里面存放的数据称为“元素”. 所有的数组都是由连续的内存位置组成.最低的地址对应第一个元素,最高的地址 ...
- D - Binary Lexicographic Sequence URAL - 1081 (贪心)
题目链接:https://cn.vjudge.net/contest/275079#problem/D 具体思路:首先,我们可以观察到1-n位数的种数连起来是一个很有规律的数列,然后我们开始倒序建立. ...
- 蓝色的oa模板html_综合信息服务管理平台OA模板——后台
链接:http://pan.baidu.com/s/1qXGGOAK 密码:2otu
- java反序列化漏洞
http://www.freebuf.com/vuls/86566.html 有时间了 仔细阅读
- 35 - 并发编程-GIL-多进程
目录 1 GIL 1.1 为什么会有GIL 1.2 GIL与thread lock 1.3 个人总结 2 multiprocessing模块 2.1 Process类 2.2 Process类的方法 ...
- Python3 re模块正则表达式中的re.S
在Python的正则表达式中,有一个参数为re.S.它表示"."(不包含外侧双引号,下同)的作用扩展到整个字符串,包括"\n".看如下代码: import re ...
- 在64位ubuntu中安装代码比较工具beyond compare
1,//从http://www.scootersoftware.com/download.php 官方地址下载 bcompare-3.3.2.14050.tar.gz 或 bcompare-4.0.7 ...