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;
}
posted @ 2021-08-21 21:05  斯文~  阅读(22)  评论(0)    收藏  举报

你好!