QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#886208 | #2211. IOI Problem Revised | NKheyuxiang | AC ✓ | 664ms | 47824kb | C++14 | 3.9kb | 2025-02-06 21:10:58 | 2025-02-07 14:42:12 |
Judging History
This is the latest submission verdict.
- [2025-02-07 14:35:59]
- hack成功,自动添加数据
- (/hack/1532)
- [2025-02-06 21:10:58]
- Submitted
answer
#include<bits/stdc++.h>
#define N 400005
#define PR pair<int ,int >
#define fi first
#define se second
#define mp make_pair
using namespace std;
const long long inf=1e18;
int n,k;
long long L,a[N],pre[N];
long long calc(int l,int r){
int x=(r-l)/2;
return (pre[r]-pre[r-x])-(pre[l+x]-pre[l]);
}
int tl,hd,st[N],pr[N];
long long f[N];
int g[N];
int sol_L(long long x){
f[0]=0;g[0]=0;
tl=hd=1;st[1]=0;pr[1]=n;
for(int i=1;i<=n;i++){
int v=st[tl];
f[i]=f[v]+calc(v,i)+x;
g[i]=g[v]+1;
if(pr[tl]<=i) tl++;
pr[tl-1]=i;
while(hd>tl&&f[i]+calc(i,pr[hd-1]+1)<f[st[hd]]+calc(st[hd],pr[hd-1]+1)) hd--;
int l=pr[hd-1]+1,r=pr[hd];
while(l<=r){
int mid=(l+r)/2;
if(f[i]+calc(i,mid)<f[st[hd]]+calc(st[hd],mid)) r=mid-1;
else l=mid+1;
}
if(l==pr[hd-1]+1) hd--;
else pr[hd]=l-1;
st[++hd]=i,pr[hd]=n;
}
return g[n];
}
int sol_R(long long x){
f[0]=0;g[0]=0;
tl=hd=1;st[1]=0;pr[1]=n;
for(int i=1;i<=n;i++){
int v=st[tl];
f[i]=f[v]+calc(v,i)+x;
g[i]=g[v]+1;
if(pr[tl]<=i) tl++;
pr[tl-1]=i;
while(hd>tl&&f[i]+calc(i,pr[hd-1]+1)<=f[st[hd]]+calc(st[hd],pr[hd-1]+1)) hd--;
int l=pr[hd-1]+1,r=pr[hd];
while(l<=r){
int mid=(l+r)/2;
if(f[i]+calc(i,mid)<=f[st[hd]]+calc(st[hd],mid)) r=mid-1;
else l=mid+1;
}
if(l==pr[hd-1]+1) hd--;
else pr[hd]=l-1;
st[++hd]=i,pr[hd]=n;
}
return g[n];
}
int gl[N],gr[N];
int pos[N];
void find(){
long long l=1,r=1e17;
while(l<=r){
long long mid=(l+r)/2;
if(sol_R(mid)<k) r=mid-1;
else l=mid+1;
}
sol_L(r);
for(int i=0;i<=n;i++) gl[i]=g[i];
sol_R(r);
for(int i=0;i<=n;i++) gr[i]=g[i];
pos[k]=n;
for(int i=n-1,j=k-1;i>0;i--){
if(gl[i]<=j&&j<=gr[i]&&f[i]+calc(i,pos[j+1])+r==f[pos[j+1]])
pos[j]=i,j--;
}
pos[0]=0;
}
long long ff[N];
void dnc(int ql,int qr,int l,int r){
if(ql>qr) return;
int mid=(ql+qr)/2;
ff[mid]=inf;
for(int i=l;i<=r;i++){
long long w=f[i]+calc(i,mid);
if(w<ff[mid]) ff[mid]=w,g[mid]=i;
}
dnc(ql,mid-1,l,g[mid]);
dnc(mid+1,qr,g[mid],r);
}
vector<int > anp[N];
long long anv[N];
void run(vector<PR > ss){
int ql=ss[0].fi,qr=ss[0].se;
int u=(ql+qr)/2;
for(int i=ss[1].fi;i<=ss[1].se;i++)
f[i]=calc(u,i),g[i]=gl[i]=u;
for(int i=1;i<k-1;i++){
dnc(ss[i+1].fi,ss[i+1].se,ss[i].fi,ss[i].se);
gl[ss[i+1].se]=g[ss[i+1].se];
for(int j=ss[i+1].fi;j<=ss[i+1].se;j++) f[j]=ff[j];
}
anv[u]=inf;int pp=0;
for(int i=ss[k-1].fi;i<=ss[k-1].se;i++){
long long w=f[i]+calc(i,u+n);
if(w<anv[u]) anv[u]=w,pp=i;
}
anp[u].push_back(pp);
for(int i=k-1;i>0;i--){
pp=(pp==ss[i].se?gl[pp]:g[pp]);
anp[u].push_back(pp);
}
for(int i=0;i<k-1-i;i++) swap(anp[u][i],anp[u][k-1-i]);
vector<PR > ttl,ttr;
if(ql<u){
ttl.push_back(mp(ql,u-1));
for(int i=1;i<k;i++)
ttl.push_back(mp(ss[i].fi,anp[u][i]));
run(ttl);
}
if(u<qr){
ttr.push_back(mp(u+1,qr));
for(int i=1;i<k;i++)
ttr.push_back(mp(anp[u][i],ss[i].se));
run(ttr);
}
}
long long out[N];
int main(){
scanf("%d%d%lld",&n,&k,&L);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]),a[i+n]=a[i]+L;
for(int i=1;i<=2*n;i++)
pre[i]=pre[i-1]+a[i];
if(k==1){
long long mv=inf,ap=0;
for(int i=0;i<n;i++){
long long w=calc(i,i+n);
if(w<mv) mv=w,ap=a[i+(n+1)/2];
}
ap%=L;
printf("%lld\n%lld\n",mv,ap);
return 0;
}
find();
int mnl=n+1,idm=0;
for(int i=0;i<k;i++){
if(pos[i+1]-pos[i]<mnl)
mnl=pos[i+1]-pos[i],idm=i;
}
for(int i=k+1;i<=k+idm;i++) pos[i]=pos[i-k]+n;
for(int i=0;i<=k;i++) pos[i]=pos[i+idm];
vector<PR > ss;
for(int i=0;i<k;i++) ss.push_back(mp(pos[i],pos[i+1]));
run(ss);
long long mnv=inf;
int aid=0;
for(int i=ss[0].fi;i<=ss[0].se;i++){
if(anv[i]<mnv) mnv=anv[i],aid=i;
}
printf("%lld\n",mnv);
anp[aid].push_back(aid+n);
for(int i=0;i<k;i++) out[i]=a[(anp[aid][i]+anp[aid][i+1])/2+1]%L;
sort(out,out+k);
for(int i=0;i<k;i++) printf("%lld ",out[i]);
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 30504kb
Test #2:
score: 0
Accepted
time: 3ms
memory: 28496kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 30348kb
Test #4:
score: 0
Accepted
time: 2ms
memory: 30548kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 30384kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 30552kb
Test #7:
score: 0
Accepted
time: 3ms
memory: 32460kb
Test #8:
score: 0
Accepted
time: 3ms
memory: 30576kb
Test #9:
score: 0
Accepted
time: 8ms
memory: 30632kb
Test #10:
score: 0
Accepted
time: 7ms
memory: 34668kb
Test #11:
score: 0
Accepted
time: 83ms
memory: 31260kb
Test #12:
score: 0
Accepted
time: 82ms
memory: 31604kb
Test #13:
score: 0
Accepted
time: 89ms
memory: 33244kb
Test #14:
score: 0
Accepted
time: 85ms
memory: 33536kb
Test #15:
score: 0
Accepted
time: 81ms
memory: 33380kb
Test #16:
score: 0
Accepted
time: 625ms
memory: 45468kb
Test #17:
score: 0
Accepted
time: 602ms
memory: 41152kb
Test #18:
score: 0
Accepted
time: 602ms
memory: 41584kb
Test #19:
score: 0
Accepted
time: 605ms
memory: 38368kb
Test #20:
score: 0
Accepted
time: 632ms
memory: 47612kb
Test #21:
score: 0
Accepted
time: 635ms
memory: 45392kb
Test #22:
score: 0
Accepted
time: 627ms
memory: 45752kb
Test #23:
score: 0
Accepted
time: 593ms
memory: 39756kb
Test #24:
score: 0
Accepted
time: 600ms
memory: 40756kb
Test #25:
score: 0
Accepted
time: 618ms
memory: 41896kb
Test #26:
score: 0
Accepted
time: 588ms
memory: 39524kb
Test #27:
score: 0
Accepted
time: 590ms
memory: 39780kb
Test #28:
score: 0
Accepted
time: 616ms
memory: 43844kb
Test #29:
score: 0
Accepted
time: 592ms
memory: 39940kb
Test #30:
score: 0
Accepted
time: 659ms
memory: 46668kb
Test #31:
score: 0
Accepted
time: 625ms
memory: 44720kb
Test #32:
score: 0
Accepted
time: 626ms
memory: 45336kb
Test #33:
score: 0
Accepted
time: 638ms
memory: 45612kb
Test #34:
score: 0
Accepted
time: 606ms
memory: 44648kb
Test #35:
score: 0
Accepted
time: 618ms
memory: 45628kb
Test #36:
score: 0
Accepted
time: 664ms
memory: 46032kb
Test #37:
score: 0
Accepted
time: 610ms
memory: 46716kb
Test #38:
score: 0
Accepted
time: 646ms
memory: 47824kb
Test #39:
score: 0
Accepted
time: 607ms
memory: 37804kb
Test #40:
score: 0
Accepted
time: 643ms
memory: 46216kb
Test #41:
score: 0
Accepted
time: 612ms
memory: 37944kb
Test #42:
score: 0
Accepted
time: 634ms
memory: 45780kb
Test #43:
score: 0
Accepted
time: 603ms
memory: 38180kb
Test #44:
score: 0
Accepted
time: 637ms
memory: 45772kb
Test #45:
score: 0
Accepted
time: 650ms
memory: 46156kb
Test #46:
score: 0
Accepted
time: 641ms
memory: 45780kb
Test #47:
score: 0
Accepted
time: 581ms
memory: 40364kb
Test #48:
score: 0
Accepted
time: 593ms
memory: 38640kb
Test #49:
score: 0
Accepted
time: 596ms
memory: 41484kb
Test #50:
score: 0
Accepted
time: 605ms
memory: 43756kb
Test #51:
score: 0
Accepted
time: 621ms
memory: 44644kb
Test #52:
score: 0
Accepted
time: 625ms
memory: 46884kb
Test #53:
score: 0
Accepted
time: 582ms
memory: 39084kb
Test #54:
score: 0
Accepted
time: 579ms
memory: 39708kb
Test #55:
score: 0
Accepted
time: 629ms
memory: 45588kb
Test #56:
score: 0
Accepted
time: 590ms
memory: 37872kb
Test #57:
score: 0
Accepted
time: 582ms
memory: 42044kb
Test #58:
score: 0
Accepted
time: 581ms
memory: 40836kb
Test #59:
score: 0
Accepted
time: 605ms
memory: 43536kb
Test #60:
score: 0
Accepted
time: 657ms
memory: 46184kb
Test #61:
score: 0
Accepted
time: 592ms
memory: 39664kb
Test #62:
score: 0
Accepted
time: 607ms
memory: 43656kb
Test #63:
score: 0
Accepted
time: 606ms
memory: 39704kb
Test #64:
score: 0
Accepted
time: 640ms
memory: 46048kb
Test #65:
score: 0
Accepted
time: 517ms
memory: 37848kb
Test #66:
score: 0
Accepted
time: 504ms
memory: 40948kb
Test #67:
score: 0
Accepted
time: 482ms
memory: 40964kb
Test #68:
score: 0
Accepted
time: 492ms
memory: 41420kb
Test #69:
score: 0
Accepted
time: 647ms
memory: 38100kb
Test #70:
score: 0
Accepted
time: 645ms
memory: 37564kb
Test #71:
score: 0
Accepted
time: 655ms
memory: 37688kb
Test #72:
score: 0
Accepted
time: 654ms
memory: 37968kb
Extra Test:
score: 0
Extra Test Passed