单调栈
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int stack[N], top = 0;
void push(int x) {
stack[top++] = x;
}
int pop() {
return stack[--top];
}
bool empty() {
return top == 0;
}
int peek() {
return stack[top - 1];
}
/**
* acwing 830-单调栈
* @return
*/
int main() {
int m;
cin >> m;
while (m--) {
int x;
cin >> x;
while (!empty() && peek() >= x) pop();
if (empty()) cout << "-1" << ' ';
else cout << peek() << ' ';
push(x);
}
return 0;
}