From 0a2db0a7d41323bc87ceed6c5dd40a3f6ff2f9eb Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sun, 18 Aug 2024 12:06:33 +0800 Subject: [PATCH] update --- day14/P5788/1.ans | 1 + day14/P5788/1.in | 2 ++ day14/P5788/P5788.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++ day14/P5788/P5788.json | 7 ++++++ 4 files changed, 60 insertions(+) create mode 100644 day14/P5788/1.ans create mode 100644 day14/P5788/1.in create mode 100644 day14/P5788/P5788.json diff --git a/day14/P5788/1.ans b/day14/P5788/1.ans new file mode 100644 index 0000000..befeff3 --- /dev/null +++ b/day14/P5788/1.ans @@ -0,0 +1 @@ +2 5 4 5 0 \ No newline at end of file diff --git a/day14/P5788/1.in b/day14/P5788/1.in new file mode 100644 index 0000000..195dc86 --- /dev/null +++ b/day14/P5788/1.in @@ -0,0 +1,2 @@ +5 +1 4 2 3 5 \ No newline at end of file diff --git a/day14/P5788/P5788.cpp b/day14/P5788/P5788.cpp index e69de29..6282989 100644 --- a/day14/P5788/P5788.cpp +++ b/day14/P5788/P5788.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include +using namespace std; + +const int MAX_N=3e6+5; +int readInt(); +int a[MAX_N]; +int ans[MAX_N]; +stacks; + +int main(){ + const int n=readInt(); + for(int i=1;i<=n;i++){ + a[i]=readInt(); + } + ans[n]=0; + s.push(n); + for(int i=n-1;i>=1;i--){ + if (a[i]>=a[s.top()]) { + ans[i]=0; + s.push(i); + }else{ + ans[i]=s.top(); + while (s.size()>0&&a[s.top()]>a[i]) { + s.pop(); + } + s.push(i); + } + } + for(int i=1;i<=n;i++){ + cout<