社区讨论
关于P8975
学术版参与者 4已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @mknxk917
- 此快照首次捕获于
- 2026/01/21 19:19 4 周前
- 此快照最后确认于
- 2026/01/22 13:08 4 周前
使用如下代码可以通过磁体:
CPP#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e7+5;
int n,k,a[maxn],bit[maxn],tot,L,cur,nw,pre[maxn];
int smax[maxn],pmax[maxn],pos[maxn],neg[maxn],ans;
deque<int>que;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
for (int i=1;i<=n;i++)
cin>>a[i];
for (int i=1;i<=n;i++){
pre[i]=tot;
if (a[i]==0){
pos[i]=1;
neg[i]=-1;
bit[++tot]=i;
}else{
pos[i]=a[i];
neg[i]=a[i];
}
}
for (int i=1;i<=n;i++){
pos[i]+=pos[i-1];
neg[i]+=neg[i-1];
}
pmax[n+1]=smax[n+1]=-2e9;
for (int i=n;i>=1;i--){
pmax[i]=max(pmax[i+1],pos[i]);
smax[i]=max(smax[i+1],neg[i]);
}
que.push_back(n+2);
for (int i=0;i<=n;i++){
while (!que.empty() && que.front()<i)
que.pop_front();
L=pre[i];
if (L+k+1>tot){
int tmp1=pmax[i+1]-pos[i];
ans=max(ans,tmp1);
//cout<<i<<' '<<tmp1<<'\n';
}else{
cur=bit[L+k+1];
for (int j=nw+1;j<cur;j++){
while(!que.empty() && pos[que.back()]<pos[j])
que.pop_back();
que.push_back(j);
}
nw=cur-1;
int tmp1=pos[que.front()]-pos[i];
int tmp2=smax[cur]-neg[i]+k*2;
ans=max({ans,tmp1,tmp2});
//cout<<i<<' '<<tmp1<<' '<<tmp2<<'\n';
}
}
cout<<ans;
return 0;
}
https://www.luogu.com.cn/record/258454361
然而在大力对拍时,我发现了这组数据:
204 12 -1 -1 -1 -1 0 1 -1 -1 0 1 0 -1 -1 1 -1 0 0 0 -1 -1 -1 -1 1 0 -1 -1 0 -1 -1 0 -1 -1 -1 -1 0 -1 0 -1 -1 0 -1 0 0 0 0 -1 -1 1 1 0 -1 -1 0 -1 -1 0 0 0 1 0 0 -1 -1 0 0 1 -1 1 -1 -1 -1 0 0 0 -1 -1 -1 -1 -1 -1 -1 1 -1 0 -1 -1 0 -1 0 -1 0 -1 -1 0 0 -1 0 -1 -1 -1 0 -1 1 0 -1 -1 1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 0 0 0 1 -1 1 -1 -1 1 0 0 1 0 0 0 1 -1 -1 0 -1 -1 0 0 -1 0 -1 -1 1 0 -1 -1 -1 -1 -1 0 -1 -1 0 0 -1 -1 -1 -1 -1 1 0 -1 -1 -1 -1 1 0 1 -1 1 -1 -1 -1 0 -1 -1 1 -1 0 -1 -1 -1 1 0 -1 -1 0 -1 -1 -1 0 -1 -1 0 0 0 1 -1 -1 0 0 1(有点乱,见谅)使用tj,输出为10,而我的代码输出的是17。
我想知道的是,我的code错在了哪,或者这组数据是什么地方使我的code挂掉了
/bx/bx/bx
回复
共 6 条回复,欢迎继续交流。
正在加载回复...