Tree-like array simulates the sort of 3 elements codeforces 12D Ball

Source: Internet
Author: User
Tags integer numbers

http://codeforces.com/problemset/problem/12/d

Balltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

NLadies 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 theI-th Lady by Bi , her intellect by ii and her richness by Ri . ThenI-th Lady is a probable self-murderer if there is someJ-th lady thatBI? <?BJ,?II? <?IJ,?RI? <?RJ. Find the number of probable self-murderers.

Input

The first line contains one integerN(1?≤? N? ≤?500000). The second line containsNInteger numbers Bi , separated by single spaces. The third and the fourth lines contain sequences ii and Ri In the same format. It's Guaranteed that0?≤? B i,? I i,? R i? ≤?109 .

Output

Output the answer to the problem.

Sample Test (s) input
31 4 24 3 22 5 3
Output
1
Simulating the ordering of 3 elements

#include <stdio.h> #include <iostream> #include <string.h> #include <set> #include <vector > #include <map> #include <math.h> #include <queue> #include <string> #include <stdlib.h > #include <algorithm>using namespace std; #define N 500005#define ll intll n;ll C[n], Maxn;inline ll Lowbit (ll x) {R Eturn x& (-X);} void Change (ll pos, ll Val) {while (POS) C[pos]=max (C[pos],val), Pos-=lowbit (POS);} LL Maxx (ll pos) {ll ans = -1;while (pos<=maxn) ans = max (Ans,c[pos]), Pos+=lowbit (POS); return ans;} struct NODE{LL b[3],num;} W[n];bool cmp0 (node x, node Y) {return x.b[0]<y.b[0];} BOOL Cmp1 (node x, node Y) {return x.b[1]>y.b[1];} int main () {ll i,j;while (cin>>n) {for (i=0;i<n;i++) scanf ("%d", &w[i].b[0]), and for (i=0;i<n;i++) scanf ("%d ", &w[i].b[1]); for (i=0;i<n;i++) scanf ("%d ", &w[i].b[2]); sort (w, w+n, cmp0); ll rank = 1;w[0].num = 1;for (i=1;i <n;i++) {if (w[i].b[0]==w[i-1].b[0]) W[i].num = Rank;else w[i].num = ++rank;} Sort (W,W+N,CMP1); for (i=1;i<=rank;i++) C[i]=-1;maxn = Rank;i = 0;ll ans = 0;while (i<n) {for (j = i; J < n && w[i].b[1] = = w[j].b[1]; j + +) if (Maxx (w[j].num+1) >w[j].b[2]) ans++;for (j = i; J < n && w[i].b[1] = = W[j].b[1]; j + +) Change (W[j].num, W[j ].B[2]); i = j;} Cout<<ans<<endl;} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Tree-like array simulates the sort of 3 elements codeforces 12D Ball

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.