diff --git a/day14/P5788/P5788.cpp b/day14/P5788/P5788.cpp index 6282989..7a673c6 100644 --- a/day14/P5788/P5788.cpp +++ b/day14/P5788/P5788.cpp @@ -15,19 +15,10 @@ int main(){ 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=n;i>=1;i--){ + while(!s.empty()&&a[s.top()]<=a[i])s.pop(); + ans[i]=s.empty()?0:s.top(); + s.push(i); } for(int i=1;i<=n;i++){ cout<