zoukankan      html  css  js  c++  java
  • 《洛谷P2659 美丽的序列》

    算下作为最小值的最大长度,然后找下最大的。

    // Author: levil
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 2e6+5;
    const int M = 1e6+5;
    const LL Mod = 1e9+7;
    #define rg register
    #define pi acos(-1)
    #define INF 1e9
    #define CT0 cin.tie(0),cout.tie(0)
    #define IO ios::sync_with_stdio(false)
    #define dbg(ax) cout << "now this num is " << ax << endl;
    namespace FASTIO{
        inline LL read(){
            LL x = 0,f = 1;char c = getchar();
            while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
            while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
            return x*f;
        }
        void print(int x){
            if(x < 0){x = -x;putchar('-');}
            if(x > 9) print(x/10);
            putchar(x%10+'0');
        }
    }
    using namespace FASTIO;
    void FRE(){/*freopen("data1.in","r",stdin);
    freopen("data1.out","w",stdout);*/}
    
    int a[N],L[N],r[N],S[N];
    int main()
    {
        int n;n = read();
        for(rg int i = 1;i <= n;++i) a[i] = read();
        int top = 0;
        S[++top] = 0;
        a[0] = -1,a[n+1] = -1;
        for(rg int i = 1;i <= n+1;++i)
        {
            while(top != 0 && a[i] < a[S[top]])
            {
                r[S[top]] = i;
                L[S[top]] = S[top-1];
                top--;
            }
            S[++top] = i;
        }
        LL ans = -1;
        for(rg int i = 1;i <= n;++i)
        {
            ans = max(ans,1LL*a[i]*(r[i]-L[i]-1));
        }
        printf("%lld
    ",ans);
       // system("pause");    
    }
    View Code
  • 相关阅读:
    mysql索引数据结构
    29. 使用参数化编写自动化测试用例
    28. Python编写自动化测试用例
    27. Unittest单元测试框架的介绍与使用
    26. 什么是单元测试
    25. Postman的使用
    24. 接口测试的意义
    23. requests安装与使用
    22. 如何编写接口文档
    21. Blog接口开发
  • 原文地址:https://www.cnblogs.com/zwjzwj/p/13675436.html
Copyright © 2011-2022 走看看