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 ...
随机推荐
- 使用jQuery 发送Ajax
jQuery AJAX 方法 AJAX 是一种与服务器交换数据的技术,可以在不重新载入整个页面的情况下更新网页的一部分. 下面的表格列出了所有的 jQuery AJAX 方法: 构建页面:jqlogi ...
- eclips配置
新建空workspace import... configMathod:main:project:eFT-Debug@eFTSlnC/C++ Aplication /media/B/testspa2. ...
- 科普NDIS封包过滤
闲言: 这个月一直在学习NDIS驱动编程,杂七杂八的资料都看个遍了,做了点笔记,捋捋思路,发上来备忘. Ps:只是小菜的一点学习笔记,没什么技术含量,不过版主如果觉得对大家稍微有点帮助的话 ...
- 【树形dp】vijos1144小胖守皇宫
细节很精妙 描述 huyichen世子事件后,xuzhenyi成了皇上特聘的御前一品侍卫. 皇宫以午门为起点,直到后宫嫔妃们的寝宫,呈一棵树的形状:某些宫殿间可以互相望见.大内保卫森严,三步一岗,五步 ...
- [LUOGU] P2716 和谐的雪花
https://www.luogu.org/problemnew/show/P2716 给出一个n*m的矩形,求里面边长最小的正方形,使得该正方形内最大值与最小值的差大于等于给定的K. 第一反应是二分 ...
- Python操作12306抢票脚本
有一段时间没有使用Python了,前几天经朋友提起一篇关于用Python实现抢火车票的文章,百度了实现抢火车票的技术细节,网上却有不少资料,也不是新鲜的东西.在了解了一些技术手段,阅读了一些大神的博文 ...
- CSS3-transform3D
CSS3 3D位移 在CSS3中3D位移主要包括两种函数translateZ()和translate3d().translate3d()函数使一个元素在三维空间移动.这种变形的特点是,使用三维向量的坐 ...
- python爬虫基础03-requests库
优雅到骨子里的Requests 本文地址:https://www.jianshu.com/p/678489e022c8 简介 上一篇文章介绍了Python的网络请求库urllib和urllib3的使用 ...
- WIN10配置MAVEN
添加新的系统环境变量M2_HOME, 并设置其值为你安装的目录MAVEN_HOME=D:\Softwares\apache-maven-3.2.2. 更新系统PATH 变量, 添加;%M2_HOME% ...
- redux学习总结
redux学习总结 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !imp ...