Ball CodeForces - 12D
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.
Input
The first line contains one integer N (1 ≤ N ≤ 500000). The second line contains Ninteger 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 题意:一个人的三个值都小于另一个人,这个人就会自杀,问有几个人自杀
题解:线段树降维,然而并不是很会
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include <vector>
#include <set>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 5e5+;
const ll mod = 1e9+; int n;
struct node
{
int x,y,z;
}a[maxn]; int h[maxn]; struct Tree
{
int l,r,Max;
}segTree[maxn<<]; void push_up(int i)
{
segTree[i].Max = max(segTree[i<<].Max,segTree[(i<<)|].Max);
}
void build(int i,int l,int r)
{
segTree[i].l = l;
segTree[i].r = r;
segTree[i].Max = ;
if(l == r)
return;
int mid = (l + r)/;
build(i<<,l,mid);
build((i<<)|,mid+,r);
} int query(int i,int l,int r)
{
if(segTree[i].l == l && segTree[i].r == r)
return segTree[i].Max;
int mid = (segTree[i].l + segTree[i].r)/;
if(r < mid)
return query(i<<,l,r);
else if(l > mid)
return query((i<<)|,l,r);
else
return max(query(i<<,l,mid),query((i<<)|,mid+,r));
}
void update(int i,int k,int val)
{
if(segTree[i].l == k && segTree[i].r == k)
{
segTree[i].Max = max(segTree[i].Max,val);
return;
}
int mid = (segTree[i].l + segTree[i].r)/;
if(k <= mid)
update(i<<,k,val);
else
update((i<<)|,k,val);
push_up(i);
}
bool comp(node x,node y)
{
if(x.x != y.x)
return x.x > y.x;
else if(x.y != y.y)
return x.y > y.y;
else
return x.z > y.z;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i].x);
for(int i=;i<=n;i++)
{
scanf("%d", &a[i].y);
h[i] = a[i].y;
}
for(int i=;i<=n;i++)
scanf("%d",&a[i].z);
sort(h+,h+n+);
int Size = unique(h+,h++n)-h-; //unique的作用是“去掉”容器中相邻元素的重复元素(不一定要求数组有序),所以如果想得到去重后的size,需要减去初始地址,lower_bound是得到地址
//cout<<Size<<endl;
build(,,Size+);
sort(a+,a++n,comp);
int preval = a[].x;
int prei,ans = ;
for(int i=;i<=n;)
{
prei = i;
for(;a[i].x == a[prei].x && i<=n;i++)
{
a[i].y = lower_bound(h+,h++Size,a[i].y)-h;
if(query(,a[i].y+,Size+)>a[i].z)
ans++;
}
for(;prei<i;prei++)
update(,a[prei].y,a[prei].z);
}
printf("%d\n",ans);
}
Ball CodeForces - 12D的更多相关文章
- Ball CodeForces - 12D (线段树)
题目链接:https://cn.vjudge.net/problem/CodeForces-12D 题目大意:给你一个人的三个信息,如果存在一个人比当前人的这三个信息都大,那么这个人就会退出,问你最终 ...
- codeforces 12D Ball
codeforces 12D Ball 这道题有两种做法 一种用树状数组/线段树维护区间最值,一种用map维护折线,昨天我刚遇见了一道类似的用STL维护折线的题目: 392D Three Arrays ...
- Codeforces 12D Ball(线段树)
N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty ...
- Codeforces 12D Ball 树形阵列模拟3排序元素
主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- Codeforces 12D Ball cdq分治
裸的cdq, 没啥好说的, 要注意mid左边和mid右边的a相同的情况. #include<bits/stdc++.h> #define LL long long #define fi f ...
- 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)
原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解 By 岩之痕 目录: 一:综述 ...
- Codeforces Gym 100015B Ball Painting 找规律
Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white ball ...
- Codeforces Beta Round #12 (Div 2 Only) D. Ball sort/map
D. Ball Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/12/D D ...
- Codeforces Round #277.5 (Div. 2)-B. BerSU Ball
http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...
随机推荐
- 关于objc.io
推荐一个特别棒的项目:objc.io 原版地址:http://www.objc.io/ 中国版地址:http://objccn.io/ 欢迎大家前去学习,如果你有不错的东西,也欢迎跟帖分享.
- 前端防御XSS
下面是前端过滤XSS的代码,取自于百度FEX前端团队的Ueditor在线编辑器: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 function xssCheck(str,r ...
- (一)JavaScript之[数据类型]与[对象]
1].数据类型字符串(String).数字(Number).布尔(Boolean).数组(Array).对象(Object).空(Null).未定义 (Undefined). //极大或极小的数字可以 ...
- NPOI Excel表格处理
//创建一个Excel文件 HSSFWorkbook work = new HSSFWorkbook(); //新建一个工作表 ISheet sheet1 = work.CreateSheet(&qu ...
- Mvc过滤器的使用【转载】
前言 在开发大项目的时候总会有相关的AOP面向切面编程的组件,而MVC(特指:Asp.Net MVC,以下皆同)项目中不想让MVC开发人员去关心和写类似身份验证,日志,异常,行为截取等这部分重复的代码 ...
- CKEditor插件开发
以前做过一个教育项目,是有关在线考试的.其中对编辑器CKEditor做了扩充,增加了插入客观题.主观题.选择题和判断题的功能.这里记述下CKEditor插件开发的过程. CKEditor以前叫FCKE ...
- Oracle VM VirtualBox 共享文件夹设置
在Windows平台下,这货完全没有VMware好用,但在Linux平台就很好用. 学校机房的电脑打开虚拟机就不能插优盘,一插优盘就卡死,所以,只好用共享文件夹了. 1.在虚拟机外部新建一个文件夹 假 ...
- 2017.10.28 QB模拟赛 —— 上午
题目链接 T1 1e18 内的立方数有 1e6个 直接枚举可过 二分最优 考场用set 死慢.. #include <cstdio> int t; long long p; int ma ...
- 安装和使用nmon监测hadoop集群性能
nmon是一个非常易用的监测Unix/Linux系统性能的小工具,可以在一个屏幕上通过指令切换,显示几乎你想要的所有指标,并且可以自动将指标周期性的保存成 .nmon格式文件,这个工具可以与nmon_ ...
- dotNetFx40_Client_x86_x64和dotNetFx40_Full_x86_x64这两个有什么区别?两个都要安装还是安装其中一个?
这个是NET Framework 4.0的安装文件它是支持生成和运行下一代应用程序和 XML Web Services 的内部 Windows 组件,很多基于此架构的程序需要它的支持才能够运行.简单的 ...