Codeforces 12 D Ball
Discription
N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can jump out of the window. He knows values of all ladies and wants to find out how many probable self-murderers will be on the ball. Lets denote beauty of the i-th lady by Bi, her intellect by Ii and her richness by Ri. Then i-th lady is a probable self-murderer if there is some j-th lady that Bi < Bj, Ii < Ij, Ri < Rj. Find the number of probable self-murderers.
The first line contains one integer N (1 ≤ N ≤ 500000). The second line contains N integer numbers Bi, separated by single spaces. The third and the fourth lines contain sequences Ii and Ri in the same format. It is guaranteed that 0 ≤ Bi, Ii, Ri ≤ 109.
Output
Output the answer to the problem.
Examples
3
1 4 2
4 3 2
2 5 3
1 先按B从大到小排序,消去一维。 然后我们依次尝试把点加入一个随着L单增R单减的二维图形上。显然这个图形可以用set维护。
当我们尝试加入一个点的时候,如果图形中第一个L比它大的点的R也比它大,那么这位女士显然就是要跳楼了;
否则我们就加入这个点,然后依次向图形的L小的一端扫,看能不能删去其他的点。 但是这么做有一个问题,就是如果B一样且L,R都满足小于的话,会被算进答案。
所以我们在之前排序的时候钦定B一样的时候按L升序排序,这样就可以避免这种情况。
#include<bits/stdc++.h>
#define ll long long
const int maxn=500005;
using namespace std;
struct node{
int x,y,z;
bool operator <(const node &u)const{
return x==u.x?y<u.y:x>u.x;
}
}a[maxn];
struct P{
int x,y;
bool operator <(const P &u)const{
return x<u.x;
}
};
set<P> s;
set<P> ::iterator it;
int n,ans=0; inline void solve(){
s.insert((P){-1,1e9+1});
s.insert((P){1e9+1,-1});
for(int i=1;i<=n;i++){
P p=(P){a[i].y,a[i].z};
it=s.upper_bound(p); if(it->y>p.y) ans++;
else{
--it;
while(it->y<=p.y){
s.erase(it);
it=--s.upper_bound(p);
}
s.insert(p);
}
}
} int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i].x);
for(int i=1;i<=n;i++) scanf("%d",&a[i].y);
for(int i=1;i<=n;i++) scanf("%d",&a[i].z);
sort(a+1,a+n+1);
solve();
printf("%d\n",ans);
return 0;
}
Codeforces 12 D Ball的更多相关文章
- Codeforces Gym 100015B Ball Painting 找规律
Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white ball ...
- CodeForces 489B BerSU Ball (贪心)
BerSU Ball 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/E Description The Berland Stat ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces 489B. BerSU Ball 解题报告
题目链接:http://codeforces.com/problemset/problem/489/B 题目意思:给出 n 个 boys 的 skills 和 m 个 girls 的 skills,要 ...
- Python list方法总结
1. 向列表的尾部添加一个新的元素 append(...) L.append(object) -- append object to end 1 2 3 4 >>> a = ['sa ...
- canvas 之 - 精灵 钟表动画
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- iOS 神秘而又强大的传感器系统 (附demo)
iOS中的各种传感器: 随着科技的发展,机器感知人的行为!Goole的无人驾驶汽车到李彦宏的无人驾汽车,都带入了各种计算及传感. 为了研究自然现象和制造劳动工具,人类必须了解外界的各类信息.了解外界信 ...
- python 各模块
01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支 ...
- Python Standard Library
Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...
随机推荐
- bootstrap历练实例:标签式的导航菜单
本章将讲解bootstrap提供的用于定义导航元素的一些选项,它使用相同的标签和基类.nav.Bootsrtap也提供了一个用于共享标记和状态的帮助器类.改变修饰的class,可以在不同的样式间进行切 ...
- shell脚本,如何写进度条。
[root@localhost ~]# cat jindutiao.sh #!/bin/bash #进度条 n=$((/)) N=$((/)) ` do sleep 0.01 [ $(($i%$n)) ...
- iOS 优秀博客
中文 iOS/Mac 开发博客列表 GitHub 上排名前 100 的 Objective-C 项目简介 GitHub 上都有哪些值得关注学习的 iOS 开源项目? iOS开发系列文章(持续更新……) ...
- JavaScript reduce() 方法
转载:http://www.runoob.com/jsref/jsref-reduce.html JavaScript Array 对象 实例 计算数组元素相加后的总和: var numbers = ...
- [LUOGU] P2593 [ZJOI2006]超级麻将
f[a][b][c][i]表示考虑到第i个,第i位用了b个,第i-1位用了a个,此时有将/无将(c=1/0)的情况是否可达. 转移分以下几类: 1.调一个将 f[a][b][1][i]|=f[a][b ...
- String中indexof函数的用法
int indexOf(int ch) 返回指定字符在此字符串中第一次出现处的索引. int indexOf(int ch, int fromIndex) 从指定的索引开始搜索,返回在此字符串中第一次 ...
- 安装tesserocr的步骤和报错RuntimeError: Failed to init API, possibly an invalid tessdata path解决办法
1,首先下载合适的tesseract-ocr的版本 2,然后安装到这一步注意要勾选这一项来安装OCR识别支持的语言包,这样OCR就可以识别多国语言,然后就可以一直点击下一步完成安装. 3,安装tess ...
- python面向对象(反射)(四)
1. isinstance, type, issubclass isinstance: 判断你给对象是否是xx类型的. (向上判断 type: 返回xxx对象的数据类型 issubclass: 判断x ...
- Android开发——Android的消息机制详解
)子线程默认是没有Looper的,Handler创建前,必须手动创建,否则会报错.通过Looper.prepare()即可为当前线程创建一个Looper,并通过Looper.loop()来开启消息循环 ...
- Linux下制作不用密码可立即登录的SSH用户
一.客户端建立两把钥匙 (1)本例以客户端的monkey用户为例,首先切换到~/.ssh目录下,如果没有该目录的话,需要进行新建 cd ~ mkdir .ssh chmod 700 .ssh cd ~ ...