hdu 1506 單調棧
阿新 • • 發佈:2017-10-02
amp efi eat gre air pair pri bits push_back
#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 單調棧