#1~6AC,#7~10WA,60pts
查看原帖
#1~6AC,#7~10WA,60pts
1049379
jhlcxoi114514楼主2024/12/28 16:21
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e6+10;
int a[N],n,l[N],r[N];
stack<int> sta;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
//	for(int i=1;i<=n;i++){
//		while(!sta.empty()&&sta.top()>a[i]) sta.pop();
//		if(sta.empty()) l[i]=-1;
//		else l[i]=sta.top();
//		sta.push(a[i]);
//	}
//	while(!sta.empty()) sta.pop();
	for(int i=n;i>=1;i--){
		while(!sta.empty()&&a[sta.top()]<a[i]) sta.pop();
		if(sta.empty()) r[i]=0;
		else r[i]=sta.top();
		sta.push(i);
	}
	for(int i=1;i<=n;i++){
		cout<<r[i]<<" ";
	}
}

悬关

2024/12/28 16:21
加载中...