标签:size 单调栈 sub 面试官 return its 大于 bsp res
10.15到场,等面试官等到11点才来,我哭
结果题是Q当年出的原题有点小幸运,4分钟就写完了,一面飘过,坐等二面GG
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6+5; int ans[maxn],val[maxn],res[maxn]; int main() { long long int n,top=0; cin>>n; for(int i=1;i<=n;++i)cin>>val[i]; for(int i=1;i<=n;++i){ res[i]=top; while(top&&val[i]>=ans[top])--top; ans[++top]=val[i]; } top = 0; memset(ans,0,sizeof(ans)); for(int i=n;i>=1;--i){ res[i]+=top; while(top&&val[i]>=ans[top])--top; ans[++top]=val[i]; } for(int i=1;i<=n;++i)cout<<res[i]+1<<‘ ‘; return 0; }
标签:size 单调栈 sub 面试官 return its 大于 bsp res
原文地址:https://www.cnblogs.com/DreamKill/p/12604066.html