社区讨论
二分T三个点求调
P3512[POI 2010] PIL-Pilots参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mlh9kn93
- 此快照首次捕获于
- 2026/02/11 08:00 上周
- 此快照最后确认于
- 2026/02/11 09:10 上周
CPP
#include<bits/stdc++.h>
using namespace std;
int k,n;
int a[3000006];
int q1[3000006],q2[3000006];
int t1,h1,t2,h2;
bool check(int t) {
memset(q1,0,sizeof(q1));
memset(q2,0,sizeof(q2));
t1=h1=t2=h2=1;
for(int l=1; l<=n; l++) {
while(h1<=t1&&a[q1[t1]]>a[l])t1--;
q1[++t1]=l;
while(h1<=t1&&q1[h1]+t<=l)h1++;
while(h2<=t2&&a[q2[t2]]<a[l])t2--;
q2[++t2]=l;
while(h2<=t2&&q2[h2]+t<=l)h2++;
if(l>=t) {
// cout<<t<<" "<<a[q2[h2]]<<" "<<a[q1[h1]]<<"\n";
if(a[q2[h2]]-a[q1[h1]]<=k)return 1;
}
}
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>k>>n;
for(int i=1; i<=n; i++) {
cin>>a[i];
}
int l=1,r=n;
while(l<r) {
int mid=l+r+1>>1;
if(check(mid))l=mid;
else r=mid-1;
}
cout<<l;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...