码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1506 单调栈

时间:2017-10-02 16:14:13      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:double   set   air   push   style   mes   out   using   pen   

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int  maxn = 2e5 + 100;
const int  maxm = 300;
//next_permutation
//priority_queue<int, vector<int>, greater<int>> que;
ll h[100005];
ll l[100005], r[100005];
int main()
{
        //freopen("bonuses.in", "r", stdin);
        //freopen("out.txt", "w", stdout);
        ll ans = 0;
        int n;
        while (cin  >> n&&n)
        {
                mem(l,0);
                mem(r,0);
                ans=0;
                for (int i = 1; i <= n; i++)
                {
                        scanf("%lld", &h[i]);
                }
                l[1] = 1, r[n] = n;
                for (int i = 1; i <= n; i++)
                {
                        int cur = i;
                        while (cur != 1 && h[cur - 1] >= h[i])
                        {
                                cur = l[cur - 1];
                        }
                        l[i] = cur;
                }
                for (int i = n - 1; i >= 1; i--)
                {
                        int cur = i;
                        while (cur != n && h[cur + 1] >= h[i])
                        {
                                cur = r[cur + 1];
                        }
                        r[i] = cur;
                }
                for (int i = 1; i <= n; i++)
                {
                        ans = max(ans, 1ll * (r[i] - l[i] + 1) * h[i]);
                }
                cout << ans << endl;
        }
}

 

hdu 1506 单调栈

标签:double   set   air   push   style   mes   out   using   pen   

原文地址:http://www.cnblogs.com/Aragaki/p/7620218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!