比赛 |
20240913练习 |
评测结果 |
AAAAAAAAAA |
题目名称 |
奶牛排队 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
0.178 s |
代码语言 |
C++ |
内存使用 |
3.88 MiB |
提交时间 |
2024-09-13 19:50:20 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e5+10;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n;
int a[N];
int st1[N],st2[N],top1,top2,ans;
int main(){
freopen("tahort.in","r",stdin);
freopen("tahort.out","w",stdout);
n = read();
for(int i = 1;i <= n;i++)a[i] = read();
for(int i = 1;i <= n;i++){
while(top1 && a[st1[top1]] < a[i])top1--;
while(top2 && a[st2[top2]] >= a[i])top2--;
int w = upper_bound(st2+1,st2+1+top2,st1[top1]) - st2;
if(w <= top2)ans = max(ans,i - st2[w] + 1);
st1[++top1] = i,st2[++top2] = i;
}
printf("%d\n",ans);
return 0;
}