https://cn.vjudge.net/problem/POJ-3250
#include<stdio.h>
#include<stack>
using namespace std;
#define ll long long
stack<ll> s;
int main()
{
ll n,m,i,j,ans,x;
scanf("%lld",&n);
ans = 0;
for(i=1;i<=n;i++)
{
scanf("%lld",&x);
if(s.size() == 0)
{
s.push(x);
}
else
{
if(s.top() > x)
{
ans += s.size();
s.push(x);
}
else
{
while(!s.empty()&&s.top() <= x)
{
s.pop();
}
ans += s.size();
s.push(x);
}
}
// printf("%d\n",ans);
}
printf("%lld\n",ans);
return 0;
}