POJ 3250 Bad Hair Day simulated monotonous Stack

Source: Internet
Author: User

POJ 3250 Bad Hair Day simulated monotonous Stack

 

Bad Hair Day
Time Limit:2000 MS   Memory Limit:65536 K
Total Submissions:14989   Accepted:4977

 

Description

Some of Farmer John'sNCows (1 ≤N≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows 'heads.

Each cowIHas a specified heightHi(1 ≤Hi≤ 1,000,000,000) and is standing in a line of cows all facing east (to the right in our diagrams). Therefore, cowICan see the tops of the heads of cows in front of her (namely cowsI+ 1,I+ 2, and so on), for as long as these cows are strictly shorter than cowI.

Consider this example:

        ==       ==   -   =         Cows facing right -->=   =   == - = = == = = = = =1 2 3 4 5 6 

Cow #1 can see the hairstyle of cows #2, 3, 4
Cow #2 can see no cow's hairstyle
Cow #3 can see the hairstyle of cow #4
Cow #4 can see no cow's hairstyle
Cow #5 can see the hairstyle of cow 6
Cow #6 can see no cows at all!

LetCiDenote the number of cows whose hairstyle is visible from cowI; Please compute the sumC1 throughCN. For this example, the desired is answer 3 + 0 + 1 + 0 + 1 + 0 = 5.

Input

Line 1: The number of cows, N.
Lines 2. N + 1: Line I+ 1 contains a single integer that is the height of cow I.

Output

Line 1: A single integer that is the sum C1 through CN.

Sample Input

610374122

Sample Output

5

 

Tell a sequence to calculate the sum of numbers smaller than each other.

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Define N 100009 typedef long ll; using namespace std; ll a [N]; int main () {int n; while (~ Scanf (% d, & n) {for (int I = 1; I <= n; I ++) scanf (% I64d, & a [I]); ll ans = 0; int B [N]; B [n] = n; for (int I = n-1; I> = 1; I --) {int tt = I; while (tt
       
         A [tt + 1]) tt = B [tt + 1]; // strictly monotonous, not equal to B [I] = tt;} // for (int I = 1; I <= n; I ++) // 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.