Codeforces-19D Point---线段树
题目链接:
https://cn.vjudge.net/problem/CodeForces-19D
题目大意:
n个操作,在200000*200000的平面上加删点
find 严格在坐标右上角,x最小,再y最小的点
解题思路:
线段树,离散化x坐标,线段树中保存y最大值,这样可以找到严格大于点x' y'的最小的x,用set存储每个x的y,就可以找到大于y'的y
#include<bits/stdc++.h>
#define mid(l, r) ((l) + ((r) - (l)) / 2)
#define lc ((o)<<1)
#define rc ((o)<<1|1)
using namespace std;
const int maxn = 1e6 + ;
typedef long long ll;
struct Edge
{
int op, x, y;
Edge(){}
Edge(int op, int x, int y):op(op), x(x), y(y){}
}a[maxn];//存储离线操作
int num[maxn];//去重
struct node
{
int l, r, y;//每个x存储最大的y
}tree[maxn];//线段树
set<int>tot[maxn];//存储x中的y void build(int o, int l, int r)
{
tree[o].l = l, tree[o].r = r, tree[o].y = -;
if(l == r)return;
int m = mid(l, r);
build(lc, l, m);
build(rc, m + , r);
}
int p;
void update(int o)
{
if(tree[o].l == tree[o].r)
{
if(tot[p].size())tree[o].y = *(--tot[p].end());
else tree[o].y = -;
return;
}
if(p <= tree[lc].r)update(lc);
else update(rc);
tree[o].y = max(tree[lc].y, tree[rc].y);
}
int query(int x, int y, int o)
{
if(tree[o].r <= x)return -;
if(tree[o].y <= y)return -;
if(tree[o].l == tree[o].r)return tree[o].l;
int t = query(x, y, lc);
if(t == -)t = query(x, y, rc);
return t;
}
int main()
{
int n;char s[];
cin >> n;
for(int i = ; i <= n; i++)
{
scanf("%s%d%d", s, &a[i].x, &a[i].y);
if(s[] == 'a')a[i].op = ;
else if(s[] == 'r')a[i].op = ;
else a[i].op = ;
num[i] = a[i].x;
}
sort(num + , num + + n);
int m = unique(num + , num + + n) - (num + );
build(, , m);
for(int i = ; i <= n; i++)
{
int x = upper_bound(num + , num + + m, a[i].x) - (num + );
int y = a[i].y;
p = x;
if(a[i].op == )
{
tot[x].insert(y);
update();
}
else if(a[i].op == )
{
tot[x].erase(y);
update();
}
else
{
int ans = query(x, y, );
if(ans == -)puts("-1");
else printf("%d %d\n", num[ans], *tot[ans].upper_bound(y));
}
}
return ;
}
Codeforces-19D Point---线段树的更多相关文章
- CodeForces 19D Points (线段树+set)
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Codeforces Beta Round #19D(Points)线段树
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Vasya and a Tree CodeForces - 1076E(线段树+dfs)
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...
- Codeforces 787D. Legacy 线段树建模+最短路
D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- codeforces 19D D. Points 树套树
D. Points Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...
- Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)
Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...
- Sereja and Brackets CodeForces - 380C (线段树+分治思路)
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...
- CodeForces 91B Queue (线段树,区间最值)
http://codeforces.com/problemset/problem/91/B B. Queue time limit per test: 2 seconds memory limit p ...
- CF 19D - Points 线段树套平衡树
题目在这: 给出三种操作: 1.增加点(x,y) 2.删除点(x,y) 3.询问在点(x,y)右上方的点,如果有相同,输出最左边的,如果还有相同,输出最低的那个点 分析: 线段树套平衡树. 我们先离散 ...
- Codeforces 343D WaterTree - 线段树, DFS序
Description Translated by @Nishikino_Maki from Luogu 行吧是我翻的 Mad scientist Mike has constructed a roo ...
随机推荐
- angular环境搭建时的坑
安装angular环境踩过一些坑,最终还是把工程跑起来了,这里描述一下我的步骤,不排除有些步骤是多余的,希望能对遇到同样问题的小伙伴有帮助. 下载最新版node.js. 安装node,安装过程一路点下 ...
- 使用 IntelliJ IDEA 创建第一个java程序 Hello World
1.首先打开新建项目窗口 1.1.选择创建java程序 1.2.Project SDK,选择jdk安装路径 1.3.Additional Libraries and Frameworks 额外的库与框 ...
- Spring与MyBatis整合上_Mapper动态代理方式
将MyBatis与Spring进行整合,主要解决的问题就是将SqlSessionFactory对象交由Spring来管理..所以该整合,只需将SQLSessionFactory的对象生成器S ...
- HDFS学习
HDFS体系结构 HDFS采用了主从(Master/Slave)结构模型,一个HDFS集群包括一个名称节点(NameNode)和若干个数据节点(DataNode)(如图所示).名称节点作为中心服务器, ...
- K:hash的应用场景
本博文主要用于讲解Hash的应用场景 Hash主要应用于数据结构中和密码学中. 用于数据结构时,主要是为了提高查询的效率,这就对速度比较重视,对抗碰撞不太看中,只要保证hash均匀分布就可以. 在密码 ...
- Python Django ORM基本增删改查
工程下的urls.py中增加如下: from cmdb import views as cmdb #要把你要操作的项目import进来 urlpatterns = [ url(r'orm', cmdb ...
- Luogu 4240:毒瘤之神的考验
传送门 Sol 分开考虑 \(\varphi(ij)\) 中 \(ij\) 的质因子 那么 \[\varphi(ij)=\frac{\varphi(i)\varphi(j)gcd(i,j)}{\var ...
- java中的>>>和>>>=
“>>>”运算符所作的是无符号的位移处理,它不会将所处理的值的最高位视为正负符号,所以作位移处理时,会直接在空出的高位填入0.当我们要作位移的原始值并非代表数值时(例如:表示颜色图素 ...
- 如何使用canvas进行2d绘图
canvas 的 2D context 可以绘制简单的 2D 图形.它的 2D context 坐标开始于 <canvas> 元素的左上角,原点坐标是(0,0).所有的坐标值都基于这个原点 ...
- C语言——循环队列和链队列的基本运算
// 循环队列#include <stdio.h> #include "SeqQue.h" // 循环队列的基本运算 /* const int maxsize = 20 ...