Tree array simulates the sorting of three elements Codeforces 12D Ball
Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output
NLadies 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 ofI-Th ladyBI, Her intellectIIAnd her richnessRI. ThenI-Th lady is a probable self-murderer if there is someJ-Th lady thatBILatency <latencyBJ, Bytes,IILatency <latencyIJ, Bytes,RILatency <latencyRJ. Find the number of probable self-murderers.
Input
The first line contains one integerN(1 digit ≤ DigitNLimit ≤0000500000). The second line containsNInteger numbersBI, Separated by single spaces. The third and the fourth lines contain sequencesIIAndRIIn the same format. It is guaranteed that 0 bytes ≤ bytesBI, Bytes,II, Bytes,RILimit ≤ limit 109.
Output
Output the answer to the problem.
Sample test (s) input
31 4 24 3 22 5 3
Output
1
Simulate sorting of three elements
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#includeusing namespace std;#define N 500005#define ll intll n;ll c[N], maxn;inline ll lowbit(ll x){return 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[1];}int main(){ll i,j;while(cin>>n) {for(i=0;i
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<