#9TLE90pts求调
查看原帖
#9TLE90pts求调
1468013
haozixuan70207楼主2025/2/7 15:31
#include<bits/stdc++.h>
using namespace std;
int n,maxx,h[100005],ansA[100005],ansB[100005];
stack<int>A,B;
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>h[i];
	for(int i=1;i<=n;i++){
		while(!A.empty()&&h[A.top()]>=h[i]){
			ansA[A.top()]=i-A.top();
			A.pop();
		}A.push(i);
	}while(!A.empty()){
		ansA[A.top()]=n-A.top()+1;
		A.pop();
	}for(int i=n;i>=0;i--){
		while(!B.empty()&&h[B.top()]<=h[i]){
			ansB[B.top()]=B.top()-i;
			B.pop();
		}B.push(i);
	}while(!B.empty()){
		ansB[B.top()]=B.top();	
		B.pop();
	}for(int i=n;i>0;i--)for(int j=ansA[i]-1;j>0;j--)if(ansB[j+i]>j&&j+1>maxx){
		maxx=j+1;
		break;
	}cout<<maxx;
}
2025/2/7 15:31
加载中...