求条
  • 板块P6510 奶牛排队
  • 楼主chu_yh
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/9 09:03
  • 上次更新2024/11/9 12:03:34
查看原帖
求条
1271341
chu_yh楼主2024/11/9 09:03

仅 AC#10

#include<bits/stdc++.h>
#define Make_by return
#define Chu 0;
using namespace std;
const int Max=1e5+5;
int n,h[Max],a[Max],b[Max],top_a,top_b,ans;
//a 单调递减栈 || b 单调递增栈 

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		while(top_a>0&&h[a[top_a]]>=h[i]) top_a--;
		while(top_b>0&&h[b[top_b]]<h[i]) top_b--;
		int p=upper_bound(a+1,a+top_a+1,b[top_b])-a;
		if(p!=top_a+1) ans=max(ans,i-a[p]+1);
		a[++top_a]=i,b[++top_b]=i;
	}
	printf("%d",ans);
	Make_by Chu
}
2024/11/9 09:03
加载中...