POJ - 3250 Bad Hair Day
https://vjudge.net/problem/POJ-3250
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n==0) break;
long long ans=0;
stack<int> q;
for(int i=0;i<n;i++)
{
int x;
scanf("%d",&x);
while(q.size() && q.top()<=x)
q.pop();
ans+=q.size();
q.push(x);
}
cout<<ans<<"\n";
}
return 0;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483257.html

浙公网安备 33010602011771号