标签:The n+1 load loading c++ bit ble size ase
#include <bits/stdc++.h>
const int N=200005;
int n,v,a[N],dl[N][20],dr[N][20],pre[1<<20],suf[1<<20],dp[N],W;
int main(){
scanf("%d%d",&n,&v);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
W=0;
while (v>>W) W++;
W++;
for (int i=0;i<W;i++) dl[1][i]=1,dr[n][i]=n,dr[n+1][i]=n,dl[0][i]=1;
for (int i=2;i<=n;i++)
for (int k=0;k<W;k++)
if (a[i]-a[i-1]<=(v>>k)) dl[i][k]=dl[i-1][k];
else dl[i][k]=i;
for (int i=n-1;i>=1;i--)
for (int k=0;k<W;k++)
if (a[i+1]-a[i]<=(v>>k)) dr[i][k]=dr[i+1][k];
else dr[i][k]=i;
for (int i=0;i<(1<<W);i++)
for (int k=0;k<W;k++){
if (i&(1<<k)) continue;
pre[i|(1<<k)]=std::max(pre[i|(1<<k)],dr[pre[i]+1][k]);
}
for (int i=0;i<(1<<W);i++) suf[i]=n+1;
for (int i=0;i<(1<<W);i++)
for (int k=0;k<W;k++){
if (i&(1<<k)) continue;
suf[i|(1<<k)]=std::min(suf[i|(1<<k)],dl[suf[i]-1][k]);
}
int all=(1<<W)-1-1;
memset(dp,0x3f,sizeof(dp));
for (int i=0;i<(1<<W);i+=2)
dp[pre[i]]=std::min(dp[pre[i]],suf[all^i]);
for (int i=n;i>=0;i--) dp[i]=std::min(dp[i],dp[i+1]);
for (int i=1;i<=n;i++){
if (dp[dl[i][0]-1]<=dr[i][0]+1) puts("Possible");
else puts("Impossible");
}
}
标签:The n+1 load loading c++ bit ble size ase
原文地址:https://www.cnblogs.com/flyfeather6/p/14380971.html