mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-30 20:36:26 +00:00
23 lines
389 B
C++
23 lines
389 B
C++
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int n, a;
|
||
|
stack<int> st;
|
||
|
|
||
|
int main() {
|
||
|
cin >> n;
|
||
|
for (int i = 0; i < n; i++) {
|
||
|
cin >> a;
|
||
|
while (!st.empty() && st.top() >= a) st.pop();
|
||
|
if (st.empty()) {
|
||
|
cout << -1 << ' ';
|
||
|
} else {
|
||
|
cout << st.top() << ' ';
|
||
|
}
|
||
|
st.push(a);
|
||
|
}
|
||
|
cout << endl;
|
||
|
return 0;
|
||
|
}
|