mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 16:56:26 +00:00
830. 单调栈
https://www.acwing.com/problem/content/submission/code_detail/7415280/
This commit is contained in:
parent
1ef3672428
commit
d0372f7608
22
AcWing/830/830.cpp
Normal file
22
AcWing/830/830.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user