zoukankan      html  css  js  c++  java
  • 0x11 栈

    这个不难吧,算是常识了。。毕竟也是刷过USACO的人

    对顶栈这东西前几天才遇到过,好像和在线求中位数那东西放一起了吧

    单调栈倒是没什么。。。贴个代码算了。一开始有点蠢的每个位置算,后来发现出栈再算就行了

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef long long LL;
    
    int a[110000];
    int top,sta[110000],w[110000];
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            if(n==0)break;
            for(int i=1;i<=n;i++)scanf("%d",&a[i]);
            a[++n]=0;
            
            int top=0;LL ans=0;
            for(int i=1;i<=n;i++)
            {
                int L=0;
                while(top!=0&&sta[top]>a[i])
                {
                    L+=w[top];
                    ans=max(ans, (LL(L))*(LL(sta[top])) );
                    top--;
                }
                sta[++top]=a[i];w[top]=L+1;
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
    poj2559

    呜呜呜好困昨晚嗨皮今天早上3点才睡中午又去糜烂

  • 相关阅读:
    bzoj1648:奶牛野餐
    bzoj1650:跳石子
    bzoj1643:贝西的秘密草坪
    bzoj1639:月度开支
    bzoj1636:Balanced Lineup
    bzoj1634:护花
    .
    bzoj1620:时间管理
    bzoj1611:流星雨
    bzoj1609:麻烦的聚餐
  • 原文地址:https://www.cnblogs.com/AKCqhzdy/p/9247312.html
Copyright © 2011-2022 走看看