#WA,求大佬帮忙
查看原帖
#WA,求大佬帮忙
663060
limingjie2009楼主2022/6/11 15:15
#include <queue>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <iomanip>
#include <string.h>
#include <algorithm>
using namespace std;
#define LL long long
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
int st[N],top,num[N],a[N];
int main()
{
	int n;
	cin >> n;
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		num[x]++;
		while(top > 0 && st[top] <x)
		{
			ans+=num[st [top]];
			num[st [top]]=0;
			top--;
		}
		if(st[top]!=x)
		{
			if(st[top]!=x)
				ans++;
			st[++top]=x;
		}
		else
		{
			ans+=num[st[top]];
			if(top==1)
				ans--;
		}
	}
		cout << ans << endl;
		return 0;
}
2022/6/11 15:15
加载中...