RE求调
查看原帖
RE求调
927580
zhangxiandong091228楼主2024/10/25 12:00

rt

#include <iostream>
#include <stack>
using namespace std;
typedef long long ll;
const ll NR=3e7+6; 
stack<ll> st;
ll n,a[NR],f[NR];
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(ll i=n;i>=1;i--)
	{
		if(st.empty())
		{
			f[i]=0;
		}
		else
		{
			int lin=st.top();
			while(!st.empty()&&lin<=a[i])
			{
				st.pop();
				lin=st.top();	
			}
			f[i]=lin;
		}
		st.push(i);
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<f[i]<<" ";
	}
	return 0;
}
2024/10/25 12:00
加载中...