单调栈纯板子
ACcode:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e6+10;
int n,a[N],b[N];
void solve() {
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
stack<int>st;
for(int i=n; i>=1; i--) {
while(!st.empty()&&a[i]>=a[st.top()]) st.pop();
if(st.empty()) b[i]=0;
else b[i]=st.top();
st.push(i);
}
for(int i=1; i<=n; i++) cout<<b[i]<<" ";
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int t=1;
//cin>>t;
while(t--) {
solve();
}
return 0;
}
over~