30分求调
查看原帖
30分求调
914443
gloomy_楼主2024/4/12 17:12
#include<bits/stdc++.h> 
using namespace std;
stack<int> sta;
int n,a[80005];
long long s;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=1;i--)
	{
		while(!sta.empty()&&a[sta.top()]<=a[i])
		{
			sta.pop();
		}
		if(sta.empty())
		{
			s+=n-i;
		}
		else
		{
			s+=sta.top()-i-1;
		}
		sta.push(i);
	}
	printf("%lld",s);
	return 0;
}
2024/4/12 17:12
加载中...