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 ...
随机推荐
- javaEE(14)_文件上传下载
一.文件上传概述 1.实现web开发中的文件上传功能,需完成如下二步操作: •在web页面中添加上传输入项•在servlet中读取上传文件的数据,并保存到本地硬盘中. 2.如何在web页面中添加上传输 ...
- 转: opencv4.0.0 +opencv_contrib在vs2015中编译
https://blog.csdn.net/baidu_40691432/article/details/84957737
- [LUOGU] P1387 最大正方形
题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n,m<=100),接下来n行,每行m ...
- vim的卸载以及环境的配置小记
一.背景 由于之前配置错误,导致我的YouCompleteMe这个插件不能用了,一直提示: ERROR:Required vim compiled with +python. YouCompleteM ...
- (62)zabbix客户端自动注册
1. 概述 上一篇内容<zabbix自动发现配置>,大概内容是zabbix server去扫描一个网段,把在线的主机添加到Host列表中. 我们本篇内容与上篇相反,这次是Active ag ...
- 【Charles】使用Charles时,抓不到包的情况。
有可能是因为浏览器的代理权限给了其他插件,需要停用该插件,重启浏览器,重新进行访问就可以看到Charles的抓包信息了.
- (转)Duplicate Symbol链接错的原因总结和解决方法
duplicate symbol是一种常见的链接错误,不像编译错误那样可以直接定位到问题的所在.但是经过一段时间的总结,发现这种错误总是有一些规律可以找的.例如,我们有如下的最简单的两个类代码: // ...
- PAT Basic 1066
1066 图像过滤 图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来.现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换. 输入格式: 输入在第一 ...
- android 之 Dialog
Android平台下对话框主要有普通对话框.选项对话框.单选多选对话框.进度对话框.日期对话框.时间对话框等. 在程序中通过开发回调方法onCreateDialog来完成对话框的创建,该方法需要传入代 ...
- tp 路径表示
本文实例分析了thinkphp常见路径用法.分享给大家供大家参考.具体如下: 这里介绍的标签主要有: __root__ __self__ __action__ __url__ __app__ __pu ...