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 ...
随机推荐
- 相机 感光度iso,焦距,光圈,ccd 和 噪点, 景深关系表格
表格 矩阵 感官度iso: 越低曝光速度越慢,所谓慢工出细活,成像质量会好,如果形成的话. 但是因为慢,所以要更多的光量,才能画完. 就需要更慢的快门 (但是太慢手抖的话就糊掉,或者动的物体形成轨迹. ...
- HTML5 FormData 模拟表单控件 支持异步上传二进制文件 移动端
FormData是XMLHttpRequest Level 2添加的一个新的接口,利用FormData对象,我们可以通过JavaScript用一些键值对来模拟一系列表单控件,还可以使用XMLHttpR ...
- CF547D Mike and Fish 建图
题意: 有点长→CF547DMike and Fish. 分析: 其实也没什么好分析的,我这也是看的题解. (不过,那篇题解好像文字的代码不太对劲) 这里直接说做法,正确性自证: 对输入的,将横.纵坐 ...
- MySQL 查询优化之 Index Merge
MySQL 查询优化之 Index Merge Index Merge Intersection 访问算法 Index Merge Union 访问算法 Index Merge Sort-Union ...
- laravel中的视图合成器
==================================================================================================== ...
- Template--模板
模板引擎的支持 配置 模板引擎配置为TEMPLATES设置.这是一个配置列表,每个引擎一个,默认值为空.这是settings.py生成的,通过startproject命令定义了一个更有用的值: TEM ...
- 剑指Offer(书):调整数组顺序使奇数位于偶数前面
题目:输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. public void ...
- 【转】js里的时间函数集
$(function(){ var mydate = new Date(); var t=mydate.toLocaleString(); $("#time").text(t); ...
- 关于面试总结-linux篇
前言 现在做测试的出去面试,都会被问到linux,不会几个linux指令都不好意思说自己是做测试的了,本篇收集了几个被问的频率较高的linux面试题 常用指令 1.说出10个linux常用的指令 ls ...
- [Kubernetes]深入解析Pod
Pod是Kubernetes项目的原子调度单位 为什么需要Pod? 容器是未来云计算系统中的进程,容器镜像就是这个系统里的".exe"安装包,那Kubernetes就是操作系统. ...