【BZOJ】【P2096】【Poi2010】【Pilots】【题解】【二分+单调队列】
来源:互联网 发布:淘宝淘口令在哪看 编辑:程序博客网 时间:2024/06/05 03:55
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2096
答案满足二分性质……二分+判定
nlogn好像很慢……
Code:
#include<bits/stdc++.h>using namespace std;const int maxn=3e6+5;int k,n;int a[maxn];deque<int>Min,Max;int main(){scanf("%d%d",&k,&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);int l=1,r=n+1;while(l<r){int mid=(l+r)>>1,ok=0;Min.clear();Max.clear();for(int i=1;i<=mid;i++){while(Max.size()&&a[Max.back()]<=a[i])Max.pop_back();while(Min.size()&&a[Min.back()]>=a[i])Min.pop_back();Max.push_back(i);Min.push_back(i);}if(a[Max.front()]-a[Min.front()]<=k){l=mid+1;ok=1;continue;}for(int i=1;i+mid<=n;i++){while(Max.size()&&Max.front()<=i)Max.pop_front();while(Min.size()&&Min.front()<=i)Min.pop_front();while(Max.size()&&a[Max.back()]<=a[i+mid])Max.pop_back();while(Min.size()&&a[Min.back()]>=a[i+mid])Min.pop_back();Max.push_back(i+mid);Min.push_back(i+mid);if(a[Max.front()]-a[Min.front()]<=k){l=mid+1;ok=1;break;}}if(!ok)r=mid;}cout<<l-1<<endl;return 0;}
0 0
- 【BZOJ】【P2096】【Poi2010】【Pilots】【题解】【二分+单调队列】
- BZOJ 2096: [Poi2010]Pilots 单调队列题解
- bzoj 2096: [Poi2010]Pilots (二分答案+单调队列)
- BZOJ 2096([Poi2010]Pilots-单调队列-差值)
- BZOJ 2096 Poi2010 Pilots 单调队列
- BZOJ 2096: [Poi2010]Pilots|单调队列
- bzoj 2096: [Poi2010]Pilots 单调队列
- [BZOJ 2096][Poi2010]Pilots:单调队列
- 单调队列 BZOJ 2096 [Poi2010]Pilots
- BZOJ 2096 [Poi2010]Pilots 单调队列
- [bzoj2096][Poi2010]Pilots(二分+单调队列)
- 【bzoj2096】[Poi2010]Pilots 单调队列
- [BZOJ2096][Poi2010]Pilots(单调队列)
- BZOJ 2096: pilots 单调队列
- 2096: [Poi2010]Pilots 单调队列维护最值
- [BZOJ 2096]Poi2010 Pilots
- BZOJ 2096: [Poi2010]Pilots
- BZOJ 2096 [Poi2010]Pilots
- iOS缓存方案
- function template application in class
- 动态规划第六讲——leetcode上的动态规划汇总(下)
- SQL Server 触发器
- 【算法】【转】KMP算法详解
- 【BZOJ】【P2096】【Poi2010】【Pilots】【题解】【二分+单调队列】
- NIO与传统IO的区别--通熟易懂,很经典
- error while loading shared libraries: libcudart.so.6.5: cannot open shared object file: No such file
- 社会名流问题
- 重装windows系统后恢复原来的ubuntu系统的方法
- 类模版继承
- CryptAPI RSA加密解密
- MacOX以及XCode下文件结束符(EOF)的输入
- 记录2--ubuntu保存默认的亮度