P5788代码求改
查看原帖
P5788代码求改
678115
G__G楼主2022/9/21 20:17

大神们有谁能看看这代码哪错了

#include<bits/stdc++.h>
using namespace std;
struct no{
	long long num,id;
}a[11000000];
int n;
int ans[11000000];
stack<no> s;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].num;
		a[i].id=i;
	}
	for(int i=n;i>=1;i--){
		while(!s.empty()&&s.top().num<a[i].num){
			s.pop();
		}
		ans[i]=s.top().id;
		s.push(a[i]);
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}

2022/9/21 20:17
加载中...