<sub id="ntl1z"></sub>

<sub id="ntl1z"></sub>

<thead id="ntl1z"></thead>

      POJ 2559 最大矩形。。

      栈的应用,计算每个矩形往左往右最多能扩展到哪里。

      然后再枚举一遍 O(n) 的

      #include <stdio.h>
      #include <iostream>
      #include <queue>
      #include <algorithm>
      #include <map>
      #include <vector>
      #include <cmath>
      #include <string.h>
      #include <stdlib.h>
      #include <time.h>
      #include <fstream>
      #include <set>
      #include <stack>
      #include <list>
      using namespace std;
      
      #define READ freopen("acm.in","r",stdin)
      #define WRITE freopen("acm.out","w",stdout)
      #define ll long long
      #define ull unsigned long long 
      #define uint unsigned int
      #define PII pair<int,int>
      #define PDD pair<double,double>
      #define fst first
      #define sec second
      #define MS(x,d) memset(x,d,sizeof(x))
      #define INF 0x3f3f3f3f
      #define ALL(x) x.begin(),x.end()
      #define PB push_back
      #define MOD 99991
      #define MAX 1000000
      
      int n;
      ll h[MAX];
      int r[MAX];
      int l[MAX];
      int main()
      {
          READ;
          while(scanf("%d",&n)&&n)
          {
              MS(r,0),MS(l,0);
              stack<PII> S;
              for(int i=1;i<=n;i++)
                  scanf("%lld",h+i);
              h[0]=h[n+1]=-1;
              for(int i=1;i<=n+1;i++)
              {
                  while(!S.empty()&&S.top().fst>h[i])
                      r[S.top().sec]=i-S.top().sec,S.pop();
                  S.push(PII(h[i],i));
              }        
              while(!S.empty())
                  S.pop();
              for(int i=n;i>=0;i--)
              {
                  while(!S.empty()&&S.top().fst>h[i])
                      l[S.top().sec]=S.top().sec-i,S.pop();
                  S.push(PII(h[i],i));
              }
              ll ans=-1;
              for(int i=1;i<=n;i++)
              {
                  ans=max(ans,h[i]*(r[i]+l[i]-1));
              }
              printf("%lld\n",ans);
          }
          return 0;
      }
      
      相关文章
      相关标签/搜索
      最准的特马网站20202020四肖期期准四肖三期内必出四肖期期准免费公开四肖中特1肖1码期期大公开本港台开奖现场直播 开奖结果