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 ...
随机推荐
- e.pageX、e.clientX、e.screenX、e.offsetX的区别以及元素的一些CSS属性
e.pageX,e.pageY:返回的值是相对于文档的定位,文档的左上角为(0,0),向右为正,向下为正,IE不支持: e.clientX,e.clientY:返回的值是相对于屏幕可见区域的坐标,如果 ...
- unity 和 iOS/Android 信息交互(方法调用)
参考文章均来源于[大神雨松momo]的文章. unity -> iOS // unity 程序 usingSystem.Runtime.InteropServices; usingUnityEn ...
- 如鹏网学习笔记(七)HTML基础
HTML笔记 一.HTML简介 1,HTML (Hyper Text Mark-up Language) 超文本标记语言,是一种编程语言,也可以说是一种标准.规范. 2,HTML提供了一系列标记(标签 ...
- 在ASP.NET中过滤HTML字符串总结
先记下来,以作备用! /// <summary>去除HTML标记 /// /// </summary> /// <param name="Htmls ...
- 腾讯云安全组,实现服务器外网ip访问网站
添加访问地ip出入站规则HTTP,并将云主机添加到安全组中.
- 粘性页脚 Sticky Footer 最佳方式
前段时间工作中遇到粘性页脚的需求,以前用过JS控制过,最后发现flex布局是解决这类问题的好帮手. 粘性页脚:即使没有足够的内容填充页面,也要将页脚固定到窗口的底部. <!DOCTYPE htm ...
- C#学习笔记-原型模式
题目:编写基本的简历. 实现: 创建基本的Resume类,然后主函数通过实例化Resume来写简历即可. Resume类: class Resume { private string name; pr ...
- NOI 2016 区间 解题报告
题目描述 在数轴上有 n个闭区间 [l1,r1],[l2,r2],...,[ln,rn].现在要从中选出 m 个区间,使得这 m个区间共同包含至少一个位置.换句话说,就是使得存在一个 x,使得对于每一 ...
- BZOJ4598: [Sdoi2016]模式字符串(点分治 hash)
题意 题目链接 Sol 直接考虑点分治+hash匹配 设\(up[i]\)表示\(dep \% M = i\)的从下往上恰好与前\(i\)位匹配的个数 \(down\)表示\(dep \% M = i ...
- CentOS6.5(2)----安装Tab键自动补全功能:bash-completion
首先要确保网络畅通,因为该过程要通过网络下载相关的软件包. 在 root 用户下,使用 cd ~/Downloads 命令进入下载文件夹,然后依次输入如下三个命令: [root@prime:~/Doc ...