WA求调
查看原帖
WA求调
1105015
woshizuoxia楼主2024/9/26 20:15

P5788 【模板】单调栈

#include<bits/stdc++.h>
using namespace std;
const int N=1e7;
int a[N],n,ans[N];
int main(){
	cin>>n;
	stack<int>st;
	for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=n;i>=1;i--){
			while(!st.empty()&&a[st.top()]<=a[i]) st.pop();
			if(st.empty()) ans[i]=0;
			else ans[i]=st.top();
			st.push(i);
		}
	for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}
2024/9/26 20:15
加载中...