玄关求助!!!!!!!
查看原帖
玄关求助!!!!!!!
1071829
ssssbbbbbb楼主2024/5/31 19:58

后四个点wa,如果把maxn改为100000则re

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=3000000+10;
int n,a[maxn],top=0,ans[maxn];
struct node{
	int id,hig;
}st[maxn];
signed main()
{
	cin>>n;
	memset(ans,0,sizeof(ans));
	for(int i=1;i<=n;i++){
		cin>>a[i];
		while(top>0 && st[top].hig<=a[i]){
			ans[st[top].id]=i;
			top--;
		}
		top++;
		st[top].hig=a[i];
		st[top].id=i;
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}

2024/5/31 19:58
加载中...