poj 3250 栈应用

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define Maxn 100010
using namespace std;
__int64 ans=0;
int Stack[Maxn],top;
int main()
{
    int n,i,j,a;
    while(scanf("%d",&n)!=EOF)
    {
        ans=0;
        top=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a);
            while(top>0&&Stack[top]<=a)
                top--;
            ans+=(__int64)top;
            Stack[++top]=a;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

 

posted @ 2013-08-02 15:28  fangguo  阅读(135)  评论(0编辑  收藏  举报