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 ...
随机推荐
- iOS仿今日头条滑动导航
之前写了篇博客网易首页导航封装类.网易首页导航封装类优化,今天在前两个的基础上仿下今日头条. 1.网易首页导航封装类中主要解决了上面导航的ScrollView和下面的页面的ScrollView联动的问 ...
- Knockout.js Attr绑定
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- C# 条码生成类
using System.Collections; using System.Text.RegularExpressions; namespace DotNet.Utilities { public ...
- Java自学-初识
1.Java介绍 Java是一种开发语言,人和人说话用嘴说,人和计算机说话就靠开发语言.Java编写的程序可以让计算机执行一些列命令,达到人们想要的目的.比如说想要统计一年消费情况,如果人工统计,就要 ...
- 从Linux系统安装到Web应用启动教程
概述 本文讲述web应用服务器安装配置教程,其中包括:Linux系统安装,Mysql数据库安装配置,Redis安装配置,Tomcat安装配置,MongoDB安装配置,Linux JDK安装使用,Ngi ...
- 对JDK、JRE和JVM的一些浅薄理解
JDK:JDK(Java Development Kit),顾名思义是java程序的开发包,任何java程序想要运行都需要相应版本的JDK,可以到oracle下载(下载之后自带JRE和编译工具等,无需 ...
- Oracle数据库基本操作(一) —— Oracle数据库体系结构介绍、DDL、DCL、DML
一.Oracle数据库介绍 1.基本介绍 Oracle数据库系统是美国ORACLE公司(甲骨文)提供的以分布式数据库为核心的一组软件产品,是目前最流行的客户/服务器(CLIENT/SERVER)或B/ ...
- MySQL B+树索引和哈希索引的区别(转 JD二面)
导读 在MySQL里常用的索引数据结构有B+树索引和哈希索引两种,我们来看下这两种索引数据结构的区别及其不同的应用建议. 二者区别 备注:先说下,在MySQL文档里,实际上是把B+树索引写成了BTRE ...
- attr()与prop()之全选、反选问题
获取js dom原生属性的时候最好用prop()方法,获取自己添加的属性时用attr() 原文:http://blog.sina.com.cn/s/blog_bf5ce8cc0102vuyt.html ...
- 从接口取到的JSON数据如何导入进本地SQL数据库
新手学习,求大神指点. 首先:在数据库建立表--设计字段(最好和接口说明文档里面的一致) 第一步:获取接口中的字符串:这里获取的是有转义字符的字符串 HttpWebRequest request = ...