https://blog.csdn.net/lucky52529/article/details/89155694
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int st[N], top = -1;
inline push(int x){
st[++top] = x;
}
int main(){
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++){
int x;
scanf("%d", &x);
while(~top && st[top] >= x) top--;
if(~top) printf("%d ", st[top]);
else printf("-1 ");
push(x);
}
return 0;
}