D. Ball
Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
Http://codeforces.com/problemset/problem/12/D
Descriptionn ladies attend the ball in the King ' s palace. Every lady can is described with three values:beauty, intellect and richness. King's Master of ceremonies knows that ladies is very special creatures. If Some lady understands that there was other lady at the ball which was 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 would be on the ball. Lets denote beauty of the i-th lady by Bi, she intellect by Ii and she richness by Ri. Then i-th Lady is a probable self-murderer if there are some j-th lady that Bi < Bj, Ii < Ij, Ri < Rj. Find the Nu Mber of probable self-murderers.
Input
The first line contains one integer N (1≤n≤500000). The second line contains N integers numbers Bi, separated by single spaces. The third and the fourth lines contain sequences Ii and Ri in the same format. It's 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
Test instructions
If a woman's three properties are higher than B, then B will kill herself and ask how many women have committed suicide.
Exercises
Sort, then, and then use a map
A more detailed explanation: http://blog.csdn.net/qiqijianglu/article/details/8494186
Code
//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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 1000010#defineMoD 10007#defineEPS 1e-9intNum;Charch[ -];//const int INF=0X7FFFFFFF;Const intinf=0x3f3f3f3f;/*inline void P (int x) {num=0;if (!x) {Putchar (' 0 ');p UTS (""); return;} while (x>0) ch[++num]=x%10,x/=10; while (Num) Putchar (ch[num--]+48); Puts ("");}*/inline ll read () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;} InlinevoidPintx) {Num=0;if(!x) {Putchar ('0');p UTS ("");return;} while(x>0) ch[++num]=x%Ten, x/=Ten; while(Num) Putchar (ch[num--]+ -); Puts ("");}//**************************************************************************************structnode{intA,b,c;} LA[MAXN];BOOLCMP (node Aa,node bb) {if(AA.A!=BB.A)returnaa.a<BB.A; if(aa.b!=bb.b)returnAa.b>bb.b; returnaa.c<BB.C;} Map<int,int>M;map<int,int>:: iterator it;intMain () {intn=read (); for(intI=1; i<=n;i++) la[i].a=read (); for(intI=1; i<=n;i++) la[i].b=read (); for(intI=1; i<=n;i++) la[i].c=read (); Sort (La+1, la+1+n,cmp); m[-inf]=inf; M[inf]=-inf; intans=0; for(inti=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;}
Codeforces Beta Round #12 (Div 2 only) D. Ball Sort/map