• POJ3250【单调栈】


    思路:
    维护一个单调递增的栈,对于栈顶元素<=新值来说,那么后面的,我一定看不到了,pop掉以后,那么这时候的栈的大小就是我能看到的这个刚刚pop出去元素的个数。

    //#include <bits/stdc++.h>
    #include<cstdio>
    #include<stack>
    #include<algorithm>
    using namespace std;
    
    typedef long long LL;
    const int N=1e5+10;
    
    int main()
    {
        stack<int>q;
        while(!q.empty())
            q.pop();
        LL sum=0;
        int n,t;
        scanf("%d",&n);
        scanf("%d",&t);
        q.push(t);
        for(int i=1;i<n;i++)
        {
            scanf("%d",&t);
            while(!q.empty()&&t>=q.top())
                q.pop();
            sum+=q.size();
            q.push(t);
        }
        printf("%lld
    ",sum);
        return 0;
    }
    
  • 相关阅读:
    go第二天
    go第一天
    engish
    english
    git 生成公钥
    tp5 验证码
    css处理文本折行截断
    数组对象总结(牢记)
    全局css样式
    Flexbox 弹性盒子布局
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934811.html
Copyright © 2020-2023  润新知