传送门

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

Input
3
1 4 2
4 3 2
2 5 3
Output
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的更多相关文章

  1. Ball CodeForces - 12D (线段树)

    题目链接:https://cn.vjudge.net/problem/CodeForces-12D 题目大意:给你一个人的三个信息,如果存在一个人比当前人的这三个信息都大,那么这个人就会退出,问你最终 ...

  2. codeforces 12D Ball

    codeforces 12D Ball 这道题有两种做法 一种用树状数组/线段树维护区间最值,一种用map维护折线,昨天我刚遇见了一道类似的用STL维护折线的题目: 392D Three Arrays ...

  3. Codeforces 12D Ball(线段树)

    N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty ...

  4. Codeforces 12D Ball 树形阵列模拟3排序元素

    主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...

  5. Codeforces 12D Ball cdq分治

    裸的cdq, 没啥好说的, 要注意mid左边和mid右边的a相同的情况. #include<bits/stdc++.h> #define LL long long #define fi f ...

  6. 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)

    原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解    By 岩之痕 目录: 一:综述 ...

  7. Codeforces Gym 100015B Ball Painting 找规律

    Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white ball ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Html+CSS二周目--->常用概念

    学习css几乎俩周,来总结一下 对于初学者来说,有一些基本的概念是我们应当清楚的.掌握这些概念,可以帮助你更加有效的开发,大大提高开发效率. 1.盒子模型 2.浮动(float) 3.定位(posit ...

  2. 资源管理与调度系统-YARN的基本架构与原理

    资源管理与调度系统-YARN的基本架构与原理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 为了能够对集群中的资源进行统一管理和调度,Hadoop2.0引入了数据操作系统YARN. ...

  3. canvas实例(基础)

    JS实现五子棋大战:GitHub源码 知识点总结: 第一步.基础: //获取canvas var chess = document.getElementById('chess'); //获取上下文,创 ...

  4. (三)JavaScript之[事件]与[字符串]

    5].事件**JavaScript事件:HTML事件 * HTML事件是发生在HTML元素上的事情 * HTML事件可以是[浏览器的行为],也可以是[用户的行为] * * 实例: * HTML页面完成 ...

  5. php 编译安装指导

    php 编译安装 下载源码 安装 安装后配置 下载源码 php下载地址:http://php.net/downloads.php php-7.1.11.tar.bz2 安装 安装依赖包 yum ins ...

  6. MyEclipse导入JAVA工程显示红色叉叉的解决方法

    当我们有时候导入一个新的工程的时候可能会出现以下这种情况,基本上是因为jar包路径的问题. 解决方法如下: 1.右击工程,选择properties 2.选择 Java Build Path -> ...

  7. HCNA配置浮动静态路由

    1.拓扑图 2.配置IP R1 Please press enter to start cmd line! ############ <Huawei> Dec ::-: Huawei %% ...

  8. 51NOD 1092 回文字符串 LCS

    Q:给定一个串,问需要插入多少字符才能使其成为回文串,也就是左右对称的串. 经典求LCS题,即最长公共子序列,不用连续的序列.考虑O(n^2^)解法,求LCS起码得有两个串,题中才给了一个串,另一个需 ...

  9. 笨办法学Python(九)

    习题 9: 打印,打印,打印 # Here's some new strange stuff, remember type it exactly. days = "Mon Tue Wed T ...

  10. spring-mabatis整合的配置文件

    1.spring.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...