From 8e4953349a171869913a550792e383c6c2bddfce Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 3 Aug 2021 08:19:50 +0800 Subject: [PATCH] =?UTF-8?q?P5788=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E5=8D=95=E8=B0=83=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R54824971 --- Luogu/problem/P5788/P5788.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Luogu/problem/P5788/P5788.cpp diff --git a/Luogu/problem/P5788/P5788.cpp b/Luogu/problem/P5788/P5788.cpp new file mode 100644 index 00000000..2eb25715 --- /dev/null +++ b/Luogu/problem/P5788/P5788.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int n, a[3000005], f[3000005]; +stack 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; +}