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;

}

 

你可能感兴趣的:(poj)