Tree array simulates the sorting of three elements Codeforces 12D Ball

Source: Internet
Author: User

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<
             

 

 

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.