
單調隊列
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
//declare
int n,v[200005];
stack<int> stk;
//
signed main(){
fastio;
cin>>n;
for(int i=1;i<=n;i++) cin>>v[i];
stk.push(0);
for(int i=1;i<=n;i++){
while(stk.size() && v[stk.top()] >= v[i]) stk.pop();
cout<<stk.top()<<" ";
stk.push(i);
}
cout<<"\n";
return 0;
}

發佈留言