本文共 901 字,大约阅读时间需要 3 分钟。
#includeusing namespace std;typedef long long ll;const int maxn=2e5+5;stack >s;//first存下标,second存连续区间长度 int n,a[maxn],ans[maxn]={ 0},minn=1e9+1,maxx=0;int main(){ scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]),minn=min(minn,a[i]),maxx=max(maxx,a[i]); a[++n]=0; for(int i=1;i<=n;++i) { int len=0; while(!s.empty()&&a[s.top().first]>=a[i]) { ans[len+s.top().second]=max(ans[len+s.top().second],a[s.top().first]); len+=s.top().second; s.pop(); } s.push({ i,len+1}); } for(int i=n-1;i>=1;--i) ans[i]=max(ans[i],ans[i+1]); for(int i=1;i
转载地址:http://yqewz.baihongyu.com/