0
查看原帖
0
1342927
binyage楼主2025/1/17 10:18
#include<bits/stdc++.h>	
using namespace std;
int n,x[100005],ans[100005],top=0,m;
stack<int>st;
string s;
int main()
{
	cin>>n;
	m=n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		
	}
	while(n--&&n>0)
	{
		while(st.size()&&x[st.top()]<=x[n])
		{
			st.pop();
		}
		if(st.empty())
		{
			ans[n]=0;
		}
		else
		{
			ans[n]=st.top();
		}
		st.push(n);
	}
	for(int i=1;i<=m;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}	
2025/1/17 10:18
加载中...