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 B, her intellect by I and her richness by R. Then i-th lady is a probable self-murderer if there is some j-th lady that B < B, I < I, R < R. Find the number of probable self-murderers.
Input
The first line contains one integer N (1 ≤ N ≤ 500000). The second line contains Ninteger numbers B, separated by single spaces. The third and the fourth lines contain sequences I and R in the same format. It is guaranteed that 0 ≤ B, I, R ≤ 10.
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);
}