#include<iostream>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<functional>
#include<set>
#include<map>
#include<cstdlib>
#include<vector>
#include<cmath>
#include <algorithm>
using namespace std;
stack<int> s;
int main()
{
int n,i;
cin.sync_with_stdio(false);
while (cin >> n)
{
int x;
long long num = 0;
cin >> x;
s.push(x);
for (i = 1; i < n; i++)
{
int x;
cin >> x;
while (!s.empty() && s.top() <= x)
s.pop();
num += s.size();
s.push(x);
}
printf("%lld\n", num);
}
return 0;
}
A - Bad Hair Day
最新推荐文章于 2022-03-01 10:04:38 发布