mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-13 07:58:48 +00:00
P5788 【模板】单调栈
R54824971
This commit is contained in:
parent
b5061e2296
commit
8e4953349a
24
Luogu/problem/P5788/P5788.cpp
Normal file
24
Luogu/problem/P5788/P5788.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, a[3000005], f[3000005];
|
||||
stack<int> st;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
for (int i = n; i >= 1; i--) {
|
||||
while (!st.empty() && a[st.top()] <= a[i]) st.pop();
|
||||
f[i] = st.empty() ? 0 : st.top();
|
||||
st.push(i);
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cout << f[i] << ' ';
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user