zoukankan      html  css  js  c++  java
  • Ball CodeForces

    传送门

    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
    ",ans);
    }



  • 相关阅读:
    关于GDI+的图片质量
    断点续传的Demo
    offic2007 ,offic2010安装失败 1935错误处理方案
    Easy Slider幻灯片 API
    Lazyload.js延迟加载效果
    MVC3中 多种跳转方式总结
    MVC中 DropDownList编辑默认选中的使用
    ASP.NET Session的七点认识
    easyui 的datagrid的自适应宽度的问题
    Linux常用文件操作高频使用命令
  • 原文地址:https://www.cnblogs.com/smallhester/p/10390290.html
Copyright © 2011-2022 走看看