比赛 20240913练习 评测结果 AAAAAAAAAA
题目名称 奶牛排队 最终得分 100
用户昵称 健康铀 运行时间 0.444 s
代码语言 C++ 内存使用 3.67 MiB
提交时间 2024-09-13 21:14:53
显示代码纯文本
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,s[100005],ans,cz,a1[100005],top1,a2[10005],top2;
  4. void ef()
  5. {
  6. int l=1,r=top2;
  7. while(l<=r)
  8. {
  9. int mid=(l+r)>>1;
  10. if(a2[mid]>a1[top1])
  11. r=mid-1;
  12. else l=mid+1;
  13. }
  14. cz=l;
  15. }
  16. int main(){
  17. freopen("tahort.in","r",stdin);
  18. freopen("tahort.out","w",stdout);
  19. cin>>n;
  20. for(int i=1; i<=n; i++){
  21. cin>>s[i];
  22. while(top1&&s[a1[top1]]<s[i])
  23. top1--;
  24. while(top2&&s[a2[top2]]>s[i])
  25. top2--;
  26. ef();
  27. if(cz!=top2+1)
  28. ans=max(ans,i-a2[cz]+1);
  29. a1[++top1]=i;
  30. a2[++top2]=i;
  31. }
  32. cout<<ans;
  33. return 0;
  34. }