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<