QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103418 | #2211. IOI Problem Revised | grass8cow | AC ✓ | 826ms | 35172kb | C++14 | 3.4kb | 2023-05-05 19:00:51 | 2023-05-05 19:00:53 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
ll L,X[601010],su[400110],dp[601000];
const ll I=1e18;
struct qq{int l,r,i;}q[200110];
int lp,rp,ii;
ll co(int i,int j){
if(i>=j)j+=n;
int o=(j-i)/2;
return (su[j]-su[j-o])-(su[i+o]-su[i]);
}
int c[201000][2];
bool chk(int i1,int i2,int x,int t){
ll v1=dp[i1]+co(i1,x),v2=dp[i2]+co(i2,x);
if(v1!=v2)return v1>v2;
if(t)return c[i1][t]<c[i2][t];
return c[i1][t]>c[i2][t];
}
int Sol(ll v,int t){
q[lp=rp=1]=(qq){1,n,0};
dp[0]=0;
for(int i=1;i<=n;i++){
qq e=q[lp];
dp[i]=dp[e.i]+co(e.i,i)+v;
c[i][t]=c[e.i][t]+1;
if(q[lp].l<q[lp].r)q[lp].l++;
else lp++;
while(lp<=rp&&chk(q[rp].i,i,q[rp].l,t))rp--;
if(lp>rp)q[++rp]=(qq){i+1,n,i};
else{
int l=q[rp].l+1,r=q[rp].r,z=r+1;
while(l<=r){
int mid=(l+r)>>1;
if(chk(q[rp].i,i,mid,t))z=mid,r=mid-1;
else l=mid+1;
}
q[rp].r=z-1;
if(z<=n)q[++rp]=(qq){z,n,i};
}
}
return c[n][1];
}
ll at;
void sl(){
ll l=0,r=L*n;
while(l<=r){
ll mid=(l+r)>>1;
int op=Sol(mid,1);
if(op>=m)at=mid,l=mid+1;
else r=mid-1;
}
Sol(at,1),Sol(at,0);
}
int vl[200100],vr[200010],tl[201000],tr[200100];
int rt[601000];
void print(){
int j=m,pi=n;
vector<int>P;P.push_back(n);
for(int i=n-1;i>=0;i--)if(c[i][0]+1<=j&&j<=c[i][1]+1&&dp[i]+co(i,pi)+at==dp[pi])P.push_back(i),pi=i,j--;
reverse(P.begin(),P.end());
for(int i=0;i<m;i++)vl[i]=P[i],vr[i]=P[i+1];
}
int nb[600100];
int af[601000];ll ans;
int Z[600100];
void cdq(int pl,int pr,int l,int r){
if(l>r)return;
int mid=(l+r)>>1,ik=-1;
int og=Z[ii]+mid;
dp[og]=I*3;
for(int i=pl;i<=pr;i++)if(dp[og]>dp[Z[ii-1]+i]+co(i,mid))dp[og]=dp[Z[ii-1]+i]+co(i,mid),ik=i;
rt[og]=ik;
cdq(pl,ik,l,mid-1),cdq(ik,pr,mid+1,r);
}
void gh(int h){
vl[0]=vr[0]=vl[m]=vr[m]=h,Z[0]=1;
for(int i=1;i<=m;i++)Z[i]=Z[i-1]+vr[i]-vl[i]+1;
for(int i=0;i<=m;i++)Z[i]-=(vr[i]-vl[i]+1),Z[i]-=vl[i];
dp[0]=0;
for(ii=1;ii<=m;ii++)
cdq(vl[ii-1],vr[ii-1],vl[ii],vr[ii]);
int u=h;
for(int i=m-1;i;i--)nb[i]=rt[Z[i+1]+u],u=nb[i];
nb[0]=h;
if(ans>dp[Z[m]+h]){
ans=dp[Z[m]+h];
for(int i=0;i<m;i++)af[i]=nb[i];
}
}
void sol(int l,int r){
if(l>r)return;
int h=(l+r)>>1;
gh(h);
vector<int>ff,fn;ff.push_back(0),fn.push_back(0);
for(int i=1;i<m;i++)fn.push_back(nb[i]),ff.push_back(vr[i]),vr[i]=fn[i];
sol(l,h-1);
for(int i=1;i<m;i++)vr[i]=ff[i],ff[i]=vl[i],vl[i]=fn[i];
sol(h+1,r);
}
bool vi[601000];
void gx(int l,int r){
if(l>r)r+=n;
int Z=(l+r+1)/2;
vi[(Z+n-1)%n+1]=1;
}
int main(){
scanf("%d%d%lld",&n,&m,&L);
for(int i=1;i<=n;i++)scanf("%lld",&X[i]),X[i+n]=L+X[i];
for(int i=1;i<=n*2;i++)su[i]=su[i-1]+X[i];
sl();print();int ip=-1,mi=n+1;
for(int i=0;i<m;i++)mi=min(mi,vr[i]-vl[i]);
for(int i=0;i<m;i++)if(mi==vr[i]-vl[i])ip=i;
for(int i=0;i<m;i++)tl[i]=vl[(i+ip)%m],tr[i]=vr[(i+ip)%m];
for(int i=0;i<m;i++)swap(tl[i],vl[i]),swap(tr[i],vr[i]);
ans=I*3,sol(vl[0],vr[0]);
for(int i=0;i<m;i++)gx(af[i],af[(i+1)%m]);
printf("%lld\n",ans);
for(int i=1;i<=n;i++)if(vi[i])printf("%lld ",X[i]);
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 18036kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 20052kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 20056kb
Test #4:
score: 0
Accepted
time: 1ms
memory: 20076kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 22156kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 18072kb
Test #7:
score: 0
Accepted
time: 4ms
memory: 20180kb
Test #8:
score: 0
Accepted
time: 4ms
memory: 22192kb
Test #9:
score: 0
Accepted
time: 13ms
memory: 18092kb
Test #10:
score: 0
Accepted
time: 10ms
memory: 24212kb
Test #11:
score: 0
Accepted
time: 93ms
memory: 20788kb
Test #12:
score: 0
Accepted
time: 80ms
memory: 19252kb
Test #13:
score: 0
Accepted
time: 101ms
memory: 20456kb
Test #14:
score: 0
Accepted
time: 74ms
memory: 21220kb
Test #15:
score: 0
Accepted
time: 96ms
memory: 24796kb
Test #16:
score: 0
Accepted
time: 614ms
memory: 34220kb
Test #17:
score: 0
Accepted
time: 682ms
memory: 32904kb
Test #18:
score: 0
Accepted
time: 672ms
memory: 30408kb
Test #19:
score: 0
Accepted
time: 741ms
memory: 30904kb
Test #20:
score: 0
Accepted
time: 600ms
memory: 34964kb
Test #21:
score: 0
Accepted
time: 601ms
memory: 32376kb
Test #22:
score: 0
Accepted
time: 581ms
memory: 32804kb
Test #23:
score: 0
Accepted
time: 714ms
memory: 28824kb
Test #24:
score: 0
Accepted
time: 662ms
memory: 33824kb
Test #25:
score: 0
Accepted
time: 625ms
memory: 32564kb
Test #26:
score: 0
Accepted
time: 686ms
memory: 29992kb
Test #27:
score: 0
Accepted
time: 691ms
memory: 33488kb
Test #28:
score: 0
Accepted
time: 645ms
memory: 34520kb
Test #29:
score: 0
Accepted
time: 721ms
memory: 26060kb
Test #30:
score: 0
Accepted
time: 535ms
memory: 33460kb
Test #31:
score: 0
Accepted
time: 621ms
memory: 34352kb
Test #32:
score: 0
Accepted
time: 616ms
memory: 34208kb
Test #33:
score: 0
Accepted
time: 584ms
memory: 35064kb
Test #34:
score: 0
Accepted
time: 602ms
memory: 33048kb
Test #35:
score: 0
Accepted
time: 622ms
memory: 35172kb
Test #36:
score: 0
Accepted
time: 566ms
memory: 34908kb
Test #37:
score: 0
Accepted
time: 622ms
memory: 33072kb
Test #38:
score: 0
Accepted
time: 592ms
memory: 32868kb
Test #39:
score: 0
Accepted
time: 740ms
memory: 26256kb
Test #40:
score: 0
Accepted
time: 535ms
memory: 34760kb
Test #41:
score: 0
Accepted
time: 739ms
memory: 30888kb
Test #42:
score: 0
Accepted
time: 595ms
memory: 32804kb
Test #43:
score: 0
Accepted
time: 720ms
memory: 27596kb
Test #44:
score: 0
Accepted
time: 575ms
memory: 32824kb
Test #45:
score: 0
Accepted
time: 547ms
memory: 34468kb
Test #46:
score: 0
Accepted
time: 563ms
memory: 32444kb
Test #47:
score: 0
Accepted
time: 679ms
memory: 29484kb
Test #48:
score: 0
Accepted
time: 709ms
memory: 31472kb
Test #49:
score: 0
Accepted
time: 727ms
memory: 30028kb
Test #50:
score: 0
Accepted
time: 636ms
memory: 33520kb
Test #51:
score: 0
Accepted
time: 634ms
memory: 34408kb
Test #52:
score: 0
Accepted
time: 622ms
memory: 34756kb
Test #53:
score: 0
Accepted
time: 721ms
memory: 32288kb
Test #54:
score: 0
Accepted
time: 710ms
memory: 28828kb
Test #55:
score: 0
Accepted
time: 602ms
memory: 32272kb
Test #56:
score: 0
Accepted
time: 731ms
memory: 31112kb
Test #57:
score: 0
Accepted
time: 679ms
memory: 30432kb
Test #58:
score: 0
Accepted
time: 723ms
memory: 30496kb
Test #59:
score: 0
Accepted
time: 630ms
memory: 34196kb
Test #60:
score: 0
Accepted
time: 556ms
memory: 34688kb
Test #61:
score: 0
Accepted
time: 723ms
memory: 25984kb
Test #62:
score: 0
Accepted
time: 655ms
memory: 31248kb
Test #63:
score: 0
Accepted
time: 757ms
memory: 25000kb
Test #64:
score: 0
Accepted
time: 565ms
memory: 34448kb
Test #65:
score: 0
Accepted
time: 332ms
memory: 25612kb
Test #66:
score: 0
Accepted
time: 357ms
memory: 31020kb
Test #67:
score: 0
Accepted
time: 337ms
memory: 29520kb
Test #68:
score: 0
Accepted
time: 347ms
memory: 30124kb
Test #69:
score: 0
Accepted
time: 826ms
memory: 28468kb
Test #70:
score: 0
Accepted
time: 793ms
memory: 29044kb
Test #71:
score: 0
Accepted
time: 806ms
memory: 28148kb
Test #72:
score: 0
Accepted
time: 813ms
memory: 29612kb
Extra Test:
score: 0
Extra Test Passed