题目链接:

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---线段树的更多相关文章

  1. CodeForces 19D Points (线段树+set)

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  2. Codeforces Beta Round #19D(Points)线段树

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  3. Vasya and a Tree CodeForces - 1076E(线段树+dfs)

    I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...

  4. Codeforces 787D. Legacy 线段树建模+最短路

    D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  5. codeforces 19D D. Points 树套树

    D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...

  6. Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)

    Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...

  7. Sereja and Brackets CodeForces - 380C (线段树+分治思路)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

  8. CodeForces 91B Queue (线段树,区间最值)

    http://codeforces.com/problemset/problem/91/B B. Queue time limit per test: 2 seconds memory limit p ...

  9. CF 19D - Points 线段树套平衡树

    题目在这: 给出三种操作: 1.增加点(x,y) 2.删除点(x,y) 3.询问在点(x,y)右上方的点,如果有相同,输出最左边的,如果还有相同,输出最低的那个点 分析: 线段树套平衡树. 我们先离散 ...

  10. Codeforces 343D WaterTree - 线段树, DFS序

    Description Translated by @Nishikino_Maki from Luogu 行吧是我翻的 Mad scientist Mike has constructed a roo ...

随机推荐

  1. iOS开源项目周报0209

    由OpenDigg 出品的iOS开源项目周报第七期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等.Hedwig 向 ...

  2. Orchard源码:缓存设计

    概述 从缓存失效的几种方式开始了解Orchard缓存设计 1.设置失效时间 Func<int> retrieve = () => _cacheManager.Get("te ...

  3. guava快速入门(一)

    Guava工程包含了若干被Google的 Java项目广泛依赖 的核心库,例如:集合 [collections] .缓存 [caching] .原生类型支持 [primitives support] ...

  4. mysql 登录报错:ERROR 1045 (28000)

    公司linux系统的mysql数据库root用户设置过密码,但常常用命令'mysql -u root -p'登录报错,有时又能登录.登录报错信息为: [root@localhost ~]# mysql ...

  5. 4、构造方法、this、super

    构造方法 构造方法引入 * A:构造方法的引入 在开发中经常需要在创建对象的同时明确对象的属性值,比如员工入职公司就要明确他的姓名.年龄等属性信息. 那么,创建对象就要明确属性值,那怎么解决呢?也就是 ...

  6. 撩课-Web大前端每天5道面试题-Day14

    1. 请写出至少5个html5新增的标签,并说明其语义和应用场景? section:定义文档中的一个章节; nav:定义只包含导航链接的章节; header:定义页面或章节的头部; 它经常包含 log ...

  7. 2.springioc实例化bean的三个方法

    1.构造器 也就是在上一篇讲的那个例子,调用默认的无参构造函数 2.静态工厂方法 1)创建需要执行的方法的类 public class HelloWorld { public HelloWorld() ...

  8. 解决全站字符乱码(POST和GET中文编码问题)

    1 说明 乱码问题: 获取请求参数中的乱码问题: POST请求:request.setCharacterEncoding(“utf-8”): GET请求:new String(request.getP ...

  9. Java:反射与代理

    Java世界的繁荣反射这一特性有很大功劳,可以获取全面的类型信息. /** * */ package ref; import java.lang.reflect.Field; import java. ...

  10. 在js里面比较大小必须先转换成number

    利用js里面的Number函数从对象转换成数值