QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#886208#2211. IOI Problem RevisedNKheyuxiangAC ✓664ms48228kbC++143.9kb2025-02-06 21:10:582025-02-06 21:11:03

Judging History

This is a historical verdict posted at 2025-02-06 21:11:03.

  • [2025-02-07 14:42:12]
  • 自动重测本题所有获得100分的提交记录
  • Verdict: AC
  • Time: 664ms
  • Memory: 47824kb
  • [2025-02-07 14:35:59]
  • hack成功,自动添加数据
  • (/hack/1532)
  • [2025-02-06 21:11:03]
  • Judged
  • Verdict: 100
  • Time: 664ms
  • Memory: 48228kb
  • [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: 0ms
memory: 30548kb

Test #2:

score: 0
Accepted
time: 1ms
memory: 34648kb

Test #3:

score: 0
Accepted
time: 1ms
memory: 30548kb

Test #4:

score: 0
Accepted
time: 2ms
memory: 30428kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 32588kb

Test #6:

score: 0
Accepted
time: 1ms
memory: 30548kb

Test #7:

score: 0
Accepted
time: 3ms
memory: 30576kb

Test #8:

score: 0
Accepted
time: 3ms
memory: 30588kb

Test #9:

score: 0
Accepted
time: 11ms
memory: 30632kb

Test #10:

score: 0
Accepted
time: 9ms
memory: 30644kb

Test #11:

score: 0
Accepted
time: 81ms
memory: 31260kb

Test #12:

score: 0
Accepted
time: 82ms
memory: 35384kb

Test #13:

score: 0
Accepted
time: 85ms
memory: 31204kb

Test #14:

score: 0
Accepted
time: 82ms
memory: 33540kb

Test #15:

score: 0
Accepted
time: 82ms
memory: 31336kb

Test #16:

score: 0
Accepted
time: 625ms
memory: 45688kb

Test #17:

score: 0
Accepted
time: 603ms
memory: 41544kb

Test #18:

score: 0
Accepted
time: 595ms
memory: 41372kb

Test #19:

score: 0
Accepted
time: 603ms
memory: 38172kb

Test #20:

score: 0
Accepted
time: 643ms
memory: 45564kb

Test #21:

score: 0
Accepted
time: 628ms
memory: 45520kb

Test #22:

score: 0
Accepted
time: 625ms
memory: 45980kb

Test #23:

score: 0
Accepted
time: 591ms
memory: 39708kb

Test #24:

score: 0
Accepted
time: 594ms
memory: 40952kb

Test #25:

score: 0
Accepted
time: 618ms
memory: 41956kb

Test #26:

score: 0
Accepted
time: 591ms
memory: 39752kb

Test #27:

score: 0
Accepted
time: 588ms
memory: 40132kb

Test #28:

score: 0
Accepted
time: 619ms
memory: 41864kb

Test #29:

score: 0
Accepted
time: 587ms
memory: 40648kb

Test #30:

score: 0
Accepted
time: 661ms
memory: 46444kb

Test #31:

score: 0
Accepted
time: 623ms
memory: 44968kb

Test #32:

score: 0
Accepted
time: 626ms
memory: 47512kb

Test #33:

score: 0
Accepted
time: 631ms
memory: 47656kb

Test #34:

score: 0
Accepted
time: 609ms
memory: 46744kb

Test #35:

score: 0
Accepted
time: 611ms
memory: 47516kb

Test #36:

score: 0
Accepted
time: 664ms
memory: 46152kb

Test #37:

score: 0
Accepted
time: 606ms
memory: 44668kb

Test #38:

score: 0
Accepted
time: 645ms
memory: 45760kb

Test #39:

score: 0
Accepted
time: 606ms
memory: 37804kb

Test #40:

score: 0
Accepted
time: 645ms
memory: 48132kb

Test #41:

score: 0
Accepted
time: 611ms
memory: 37864kb

Test #42:

score: 0
Accepted
time: 634ms
memory: 45656kb

Test #43:

score: 0
Accepted
time: 601ms
memory: 38164kb

Test #44:

score: 0
Accepted
time: 638ms
memory: 45980kb

Test #45:

score: 0
Accepted
time: 652ms
memory: 46376kb

Test #46:

score: 0
Accepted
time: 637ms
memory: 45800kb

Test #47:

score: 0
Accepted
time: 582ms
memory: 40300kb

Test #48:

score: 0
Accepted
time: 599ms
memory: 40468kb

Test #49:

score: 0
Accepted
time: 596ms
memory: 37660kb

Test #50:

score: 0
Accepted
time: 609ms
memory: 42060kb

Test #51:

score: 0
Accepted
time: 620ms
memory: 44656kb

Test #52:

score: 0
Accepted
time: 615ms
memory: 46924kb

Test #53:

score: 0
Accepted
time: 587ms
memory: 39312kb

Test #54:

score: 0
Accepted
time: 586ms
memory: 39152kb

Test #55:

score: 0
Accepted
time: 644ms
memory: 45588kb

Test #56:

score: 0
Accepted
time: 593ms
memory: 38092kb

Test #57:

score: 0
Accepted
time: 580ms
memory: 38772kb

Test #58:

score: 0
Accepted
time: 592ms
memory: 38788kb

Test #59:

score: 0
Accepted
time: 605ms
memory: 41624kb

Test #60:

score: 0
Accepted
time: 645ms
memory: 48228kb

Test #61:

score: 0
Accepted
time: 592ms
memory: 38828kb

Test #62:

score: 0
Accepted
time: 607ms
memory: 43652kb

Test #63:

score: 0
Accepted
time: 607ms
memory: 37724kb

Test #64:

score: 0
Accepted
time: 640ms
memory: 46176kb

Test #65:

score: 0
Accepted
time: 519ms
memory: 39664kb

Test #66:

score: 0
Accepted
time: 500ms
memory: 42896kb

Test #67:

score: 0
Accepted
time: 488ms
memory: 40964kb

Test #68:

score: 0
Accepted
time: 488ms
memory: 40944kb

Test #69:

score: 0
Accepted
time: 649ms
memory: 38076kb

Test #70:

score: 0
Accepted
time: 646ms
memory: 39612kb

Test #71:

score: 0
Accepted
time: 655ms
memory: 37692kb

Test #72:

score: 0
Accepted
time: 655ms
memory: 39868kb

Extra Test:

score: 0
Extra Test Passed