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

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+5;
const ll mod = 1e9+7;

int n;
struct node
{
    int x,y,z;
}a[maxn];

int h[maxn];

struct Tree
{
    int l,r,Max;
}segTree[maxn<<2];

void push_up(int i)
{
    segTree[i].Max = max(segTree[i<<1].Max,segTree[(i<<1)|1].Max);
}
void build(int i,int l,int r)
{
    segTree[i].l = l;
    segTree[i].r = r;
    segTree[i].Max = 0;
    if(l == r)
        return;
    int mid = (l + r)/2;
    build(i<<1,l,mid);
    build((i<<1)|1,mid+1,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)/2;
    if(r < mid)
        return query(i<<1,l,r);
    else if(l > mid)
        return query((i<<1)|1,l,r);
    else
        return max(query(i<<1,l,mid),query((i<<1)|1,mid+1,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)/2;
    if(k <= mid)
        update(i<<1,k,val);
    else
        update((i<<1)|1,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=1;i<=n;i++)
        scanf("%d",&a[i].x);
    for(int i=1;i<=n;i++)
    {
        scanf("%d", &a[i].y);
        h[i] = a[i].y;
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i].z);
    sort(h+1,h+n+1);
    int Size = unique(h+1,h+1+n)-h-1;  //unique的作用是“去掉”容器中相邻元素的重复元素(不一定要求数组有序),所以如果想得到去重后的size,需要减去初始地址,lower_bound是得到地址
    //cout<<Size<<endl;
    build(1,1,Size+1);
    sort(a+1,a+1+n,comp);
    int preval = a[1].x;
    int prei,ans = 0;
    for(int i=1;i<=n;)
    {
        prei = i;
        for(;a[i].x == a[prei].x && i<=n;i++)
        {
            a[i].y = lower_bound(h+1,h+1+Size,a[i].y)-h;
            if(query(1,a[i].y+1,Size+1)>a[i].z)
                ans++;
        }
        for(;prei<i;prei++)
            update(1,a[prei].y,a[prei].z);
    }
    printf("%d\n",ans);
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值