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

Description

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 N integer 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.

Sample Input

3
1 4 2
4 3 2
2 5 3

Sample Output

1

HINT

 

题意

如果存在A女的三个属性都比B女高,那么B女就会自杀,然后问你有多少女的自杀了

题解:

排序,之后,然后用map搞一搞

较为详细的题解:http://blog.csdn.net/qiqijianglu/article/details/8494186

代码

 

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000010
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;
const int inf=0x3f3f3f3f;
/*

inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
*/
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************

struct node
{
    int a,b,c;

}la[maxn];
bool cmp(node aa,node bb)
{
    if(aa.a!=bb.a)return aa.a<bb.a;
    if(aa.b!=bb.b)return aa.b>bb.b;
    return aa.c<bb.c;
}
map<int,int> M;
map<int,int>::iterator it;
int main()
{
    int n=read();
    for(int i=1;i<=n;i++)
        la[i].a=read();
    for(int i=1;i<=n;i++)
        la[i].b=read();
    for(int i=1;i<=n;i++)
        la[i].c=read();
    sort(la+1,la+1+n,cmp);
    M[-inf]=inf;
    M[inf]=-inf;
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        it=M.upper_bound(la[i].b);
        if(la[i].c<it->second)
            ans++;
        else
        {
            if(M[la[i].b]<la[i].c)
            {
                M[la[i].b]=la[i].c;
                for(it=--M.lower_bound(la[i].b);it->second<=la[i].c;)
                    M.erase(it--);
            }
        }
    }
    cout<<ans<<endl;
}

 

 

 

 

转载于:https://www.cnblogs.com/qscqesze/p/4595758.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值