最后4个测试点RE
查看原帖
最后4个测试点RE
304524
崔化博楼主2020/10/25 20:47
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#define N 100001
typedef long long ll;
using namespace std;
struct node {
	int xv;
	int date;
};
int main()
{
	stack<node> s;
	int n;
	node a[N] = { 0,0 };
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i].date);;
		a[i].xv = i;
	}
	for (int i = n; i >= 1; --i)
	{
		while (!s.empty() && a[i].date > s.top().date)
			s.pop();
		s.push(a[i]);
		s.pop();
		if (!s.empty())
		{
			node r = a[i];
			if (s.top().date > a[i].date)
				a[i] = s.top();
			else
				a[i].xv = 0;
			s.push(r);
		}
		else
		{
			s.push(a[i]);
			a[i].xv = 0;
		}
	}
	for (int i = 1; i <= n; ++i)
		printf("%d ", a[i].xv);
	return 0;
}
2020/10/25 20:47
加载中...