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 ...
随机推荐
- unity assetStore 常用插件
常用插件 20180723============= 教程类 =============<Mecanim Example Scenes > 官方示例场景<Surivial Shoot ...
- RabbitMQ入门教程系列
https://blog.csdn.net/column/details/18247.html
- UbuntuServer 16.04 with LNMP搭建WordPress
前几天弄了个腾讯云服务器,一时新鲜,就想着在上面搭建一个wordpress博客,前后搞了四五天,各种度娘谷歌,各种错误,不过还好,最终总算是被我搭建出来了!不啰嗦,书归正传,下面开始搭建! 目录: 一 ...
- github提交代码不用输入账号密码的解决方案
1.在命令行输入命令: git config --global credential.helper store 这一步会在用户目录下的.gitconfig文件最后添加: [credential] he ...
- [javaSE] 集合工具类(Collections-sort)
java为我们提供了一个集合的工具类,方便我们对集合进行操作,里面的方法都是静态方法. Collections.sort()方法,参数:List<T>集合对象,这个对象带着泛型,是为了保证 ...
- bnu 4067 美丽的花环
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4067 美丽的花环 Time Limit: 1000ms Case Time Limit: 1000m ...
- 原型模式(GOF23)
依赖关系的倒置 基本假设在于抽象变化的慢,而依赖于抽象的细节变化的快,所以要做到抽象不依赖于实现的细节,而实现细节应该依赖于抽象 设计模式不是代码的复用,而是经验的复用,通过分析来定义抽象和细节,不要 ...
- OpenStack IceHouse 部署 - 5 - 网络节点部署
Neutron网络服务(网络节点) 目录 [隐藏] 1 参考 2 前置工作 2.1 调整内核参数 3 安装 4 配置 4.1 keystone对接 4.2 rabbitmq对接 4.3 me ...
- python学习之老男孩python全栈第九期_day022知识点总结——初识面向对象
一. 面向对象的引入# 人狗大战 def person(name,HP,aggr,sex): person = { 'name':name, # 昵称 'HP':HP, # 生命值 'aggr':ag ...
- css常见的快捷开发代码汇总(长期更新)
http://caibaojian.com/popular-css-snippets.html