AcWing 600. 仰视奶牛
原题链接
简单
作者:
我已经不想再做刺客了
,
2022-02-25 20:30:34
,
所有人可见
,
阅读 103
#include <iostream>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std;
const int N = 1e5+10;
int n,h[N],q[N],tt;
stack<int>stk;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>h[i];
h[n+1]=1e6+10;
q[0]=n+1;
tt=0;
for(int i=n;i>=1;i--){
while(h[i]>=h[q[tt]])tt--;
if(q[tt]==n+1)stk.push(0);
else stk.push(q[tt]);
q[++tt]=i;
}
while(stk.size()){
cout<<stk.top()<<'\n';
stk.pop();
}
}