Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

维护一个不减的栈……

Posted by lqp18_31 at 2009-08-04 00:10:11 on Problem 2559
           top=0;  stack[ top ]=-100;  ans=0ll;
           for( int i=1; i<=N+1 ; i++){
                if( i<=N )
                  h=getlonglong();  //   手写的读入,又快又安全
                else h=-1;
                if( h>=stack[ top ] )  stack[ ++top ]=h,len[ top ]=1;
                else{
                     long long j=0;
                     while( stack[ top ]>h ){
                            j+=len[ top ];
                            ans=max( ans , j*(long long)stack[ top ] );
                            top--;
                     }
                     stack[ ++top ]=h;
                     len[ top ]=j+1;
                }
           }
           cout << ans << endl;

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator