单调栈 #7-10 Wa 求调
查看原帖
单调栈 #7-10 Wa 求调
637073
wujingfey楼主2023/10/10 15:19
#include<bits/stdc++.h>
using namespace std;
const int N=3*1e6+5;
int n,a[N],f[N];
int st[N],top;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	st[++top]=1;
	for(int i=2;i<=n;i++){
		while(top&&a[st[top]]<=a[i]){
			f[st[top]]=i;
			top--;
		}
		st[++top]=i;
	}
	for(int i=1;i<=n;i++) cout<<f[i]<<" ";
	return 0;
}
2023/10/10 15:19
加载中...