传送门

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);
}

最新文章

  1. C# 对多个集合和数组的操作(合并、去重复、判断)
  2. mysql int(1) 与 tinyint(1) 有什么区别?
  3. URAL 1936 Roshambo 题解
  4. 【RoR win32】新建rails项目找不到script/server的解决办法
  5. 集成Spring后HibernateTemplate实现分页
  6. Visual Studio 2013
  7. 配置centos 7 mysql
  8. uestc 1722 吴神的表白
  9. IDL 遍历 XML文档示例
  10. [html5] 学习笔记-html5音频视频
  11. htpasswd 命令详解
  12. 201621123068 Week03-面向对象入门
  13. luogu3621 城池攻占 (倍增)
  14. [Selenium] CSS3 选择器
  15. Java 如何重写对象的 equals 方法和 hashCode 方法
  16. PostgreSQL的hook机制初步学习
  17. 编译安装haproxy开启支持SSL
  18. Cocostudio学习笔记(2) Button + CheckBox
  19. Android小游戏应用---撕破美女衣服游戏
  20. 记录一下自己用jQuery写的轮播图

热门文章

  1. hdu 3586 最小代价切断根与叶子联系
  2. SpringCloud的学习记录(4)
  3. SQL Server 2008R2 18456错误解决方案
  4. springboot 修改和设置 banner
  5. 【转载】#336 - Declaring and Using a readonly Field
  6. 基于LBS的多人聊天
  7. 神奇的暴力数据结构——ODT
  8. Kruskal算法求最小生成树
  9. 轻量级HTTP服务器Nginx(配置与调试Nginx维护Nginx)
  10. skimage.io.imread vs caffe.io.load_image