NOJ1553 --- Beautiful Wils (ruler acquisition method)

Source: Internet
Author: User
Tags bitset

NOJ1553 --- Beautiful Wils (ruler acquisition method)

Problem description
To simplify the building process, XadillaX built some template on the ground. The template is a very big wall and the height of each unit may be different.

8Mao and Hungar have to choose any part of this wall as their own wall.

The part (I, j) means the wall between unit (I) and unit (j) with their heights.
What Hungar thinks a beautiful wall is that the height of each unit is unique.
Now give you a wall-template, you shoshould tell Hungar that how many ways he can choose to copy his own wall?
Input
This problem contains several cases, ends with EOF.
The first line of each case is one integer N (0 <N ≤100000) which indicates the side length (number of units) of the wall-template.
The second line contains N integers which indicate the height of each unit. (0 Output
For each case, you shoshould output the number of ways that Hungar can choose.
Sample Input

5
3 4 5 5 2
3
1 2 3

Sample output

9
6

Prompt

None

Source

Cjl

Operation

I used a ruler to take a question from Wine93. I only need to record the last appearance position of each number.

/*************************************** * *********************************> File Name: NOJ1553.cpp> Author: ALex> Mail: zchao1995@gmail.com> Created Time: thursday, April 16, 2015, 28 seconds ******************************** **************************************** /# include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           # Include
            
              # Include
             
               # Include
              
                Using namespace std; const double pi = acos (-1.0); const int inf = 0x3f3f3f; const double eps = 1e-15; typedef long LL; typedef pair
               
                 PLL; static const int N = 100100; int height [N]; int last [N]; int _ hash [N]; int main () {int n; while (~ Scanf ("% d", & n) {memset (last,-1, sizeof (last); memset (_ hash,-1, sizeof (_ hash )); for (int I = 1; I <= n; ++ I) {scanf ("% d", & height [I]); int x = _ hash [height [I]; last [I] = x; _ hash [height [I] = I;} LL ans = 0; int l = 1, r = 1, len = 0; while (1) {while (r <= n & last [r] <l) {++ len; ++ r ;}ans + = len; -- len; ++ l; if (l> r) {break ;}} cout <ans <endl ;} return 0 ;}
               
              
             
            
          
         
        
       
      
     
    
   
  

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.