QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#773939#7363. 忙碌的出题人I_be_wanna100 ✓132ms17260kbC++205.3kb2024-11-23 10:54:582024-11-23 10:54:58

Judging History

你现在查看的是最新测评结果

  • [2024-11-23 10:54:58]
  • 评测
  • 测评结果:100
  • 用时:132ms
  • 内存:17260kb
  • [2024-11-23 10:54:58]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=3.1e5;
inline LL read(){
	LL x=0,ff=1;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
	if(c=='-') ff=-1,c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return x*ff;
}
inline void output(LL x){
	if(!x) return ;
	output(x/10ll);
	putchar(x%10ll+'0');
}
inline void write(LL x){
	if(x==0){
		puts("0");
		return ;
	}
	if(x<0) putchar('-'),x=-x;
	output(x);
	putchar(' ');
}
int n;
int a[N];
int pre[N],nxt[N],st[N],top;
LL calc(LL i,LL len){
	if(len==0) return 0;
	LL posl=i-pre[i]+1,posr=nxt[i]-i+1;
	LL res=0;
	if(posl<=posr){
		if(len<=posl)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+len-1) - (i) + 1 ))*len/2;
		else if(len<=posr)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posl-1) - (i) + 1 ))*posl/2+
				( ( (i+(posl+1)-1) - (pre[i]+(posl+1)-1) + 1 ) + ( (i+len-1) - (pre[i]+len-1) + 1 ))*(len-posl)/2;
		else
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posl-1) - (i) + 1 ))*posl/2+
				( ( (i+(posl+1)-1) - (pre[i]+(posl+1)-1) + 1 ) + ( (i+posr-1) - (pre[i]+posr-1) + 1 ))*(posr-posl)/2+
				( ( (nxt[i]) - (pre[i]+(posr+1)-1) + 1 ) + ( (nxt[i]) - (pre[i]+len-1) + 1 ) )*(len-posr)/2;
	}
	else{
		if(len<=posr)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+len-1) - (i) + 1 ))*len/2;
		else if(len<=posl)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posr-1) - (i) + 1 ))*posr/2+
				( ( (nxt[i]) - (i) + 1 ) + ( (nxt[i]) - (i) + 1 ) )*(len-posr)/2;
		else
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posr-1) - (i) + 1 ))*posr/2+
				( ( (nxt[i]) - (i) + 1 ) + ( (nxt[i]) - (i) + 1 ) )*(posl-posr)/2+
				( ( (nxt[i]) - (pre[i]+(posl+1)-1) + 1 ) + ( (nxt[i]) - (pre[i]+len-1) + 1 ) )*(len-posl)/2;
	}
	return res;
}
bool check(LL mid,LL rk){
	LL res=0;
	for(int i=1;i<=n;++i){
		res+=calc(i,min(mid/a[i],nxt[i]-pre[i]+1ll));
		if(res>=rk)
			return 1;
	}
	return 0;
}
LL getrk(LL x){
	LL res=0;
	for(int i=1;i<=n;++i)
		res+=calc(i,min(x/a[i],nxt[i]-pre[i]+1ll));
	return res;
}
#define pii pair<LL,int>
#define mk make_pair
priority_queue<pii> pq;
int main(){
	LL L,R,cnt;
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	L=read();R=read();
	cnt=R-L+1;
	st[++top]=0;
	for(int i=1;i<=n;++i){
		while(top&&a[st[top]]>=a[i]) nxt[st[top--]]=i;
		pre[i]=st[top];
		st[++top]=i;
	}
	while(top>1) nxt[st[top--]]=n+1;
	for(int i=1;i<=n;++i)
		++pre[i],--nxt[i];
	LL l=0,r=3e14,st=-1;
	while(l<=r){
		LL mid=(l+r)>>1;
		if(check(mid,L))
			st=mid,r=mid-1;
		else
			l=mid+1;
	}
	LL rk_st=getrk(st);
	for(int i=1;i<=rk_st-L+1&&cnt;++i)
		write(st),--cnt;
	for(int i=1;i<=n;++i)
		if(st/a[i]+1<=nxt[i]-pre[i]+1ll){
			pq.push(mk(-(st/a[i]+1)*a[i],i));
		}
	while(!pq.empty()&&cnt){
		LL now=-pq.top().first;
		int x=pq.top().second; pq.pop();
		LL len=now/a[x];
		LL num=calc(x,len)-calc(x,len-1);
		for(int i=1;i<=num&&cnt;++i)
			write(now),--cnt;
		if(len+1<=nxt[x]-pre[x]+1ll)
			pq.push(mk(-(len+1)*a[x],x));
	}
}
/*#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=3.1e5;
inline LL read(){
	LL x=0,ff=1;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
	if(c=='-') ff=-1,c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return x*ff;
}
inline void output(LL x){
	if(!x) return ;
	output(x/10ll);
	putchar(x%10ll+'0');
}
inline void write(LL x){
	if(x==0){
		puts("0");
		return ;
	}
	if(x<0) putchar('-'),x=-x;
	output(x);
	putchar(' ');
}
int n;
int a[N];
int pre[N],nxt[N],st[N],top;
LL calc(LL i,LL len){
	if(len==0) return 0;
	LL posl=i-pre[i]+1,posr=nxt[i]-i+1;
	LL res=0;
	if(posl<=posr){
		if(len<=posl)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+len-1) - (i) + 1 ))*len/2;
		else if(len<=posr)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posl-1) - (i) + 1 ))*posl/2+
				( ( (i+(posl+1)-1) - (pre[i]+(posl+1)-1) + 1 ) + ( (i+len-1) - (pre[i]+len-1) + 1 ))*(len-posl)/2;
		else
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posl-1) - (i) + 1 ))*posl/2+
				( ( (i+(posl+1)-1) - (pre[i]+(posl+1)-1) + 1 ) + ( (i+posr-1) - (pre[i]+posr-1) + 1 ))*(posr-posl)/2+
				( ( (nxt[i]) - (pre[i]+(posr+1)-1) + 1 ) + ( (nxt[i]) - (pre[i]+len-1) + 1 ) )*(len-posr)/2;
	}
	else{
		if(len<=posr)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+len-1) - (i) + 1 ))*len/2;
		else if(len<=posl)
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posr-1) - (i) + 1 ))*posr/2+
				( ( (nxt[i]) - (i) + 1 ) + ( (nxt[i]) - (i) + 1 ) )*(len-posr)/2;
		else
			res=( ( (i+1-1) - (i) + 1 ) + ( (i+posr-1) - (i) + 1 ))*posr/2+
				( ( (nxt[i]) - (i) + 1 ) + ( (nxt[i]) - (i) + 1 ) )*(posl-posr)/2+
				( ( (nxt[i]) - (pre[i]+(posl+1)-1) + 1 ) + ( (nxt[i]) - (pre[i]+len-1) + 1 ) )*(len-posl)/2;
	}
	return res;
}
bool check(LL mid,LL rk){
	LL res=0;
	for(int i=1;i<=n;++i){
		res+=calc(i,min(mid/a[i],nxt[i]-pre[i]+1ll));
		if(res>=rk)
			return 1;
	}
	return 0;
}
LL getrk(LL x){
	LL res=0;
	for(int i=1;i<=n;++i)
		res+=calc(i,min(x/a[i],nxt[i]-pre[i]+1ll));
	return res;
}
#define pii pair<LL,int>
#define mk make_pair
priority_queue<pii> pq;
int main(){
	LL L,R,cnt;
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	L=read();R=read();
	cnt=R-L+1;
	st[++top]=0;
	for(int i=1;i<=n;++i){
		while(top&&a[st[top]]>=a[i]) nxt[st[top--]]=i;
		pre[i]=st[top];
		st[++top]=i;
	}
	while(top>1) nxt[st[top--]]=n+1;
	}
}*/

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 5708kb

input:

500
614716456 379652456 778509712 908766285 482626557 775970238 477579092 475111040 84033329 300444417 73431560 147109232 243351359 715651776 906589179 979825146 111392720 740354295 71803884 532698029 901967612 380599137 384828710 272583565 663907168 748042444 701204179 407381195 718652356 837391507...

output:

1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 1388847207 138...

result:

ok single line: '1388847207 1388847207 13888472...10184949 1510184949 1510184949 '

Test #2:

score: 10
Accepted
time: 0ms
memory: 5584kb

input:

500
27970085 842848466 559426210 242855004 760446676 861565918 507012688 557418543 925681060 348998349 475224243 565932854 537313762 539258245 430870181 530136386 574122855 163938228 132232929 509292002 637264372 773813857 461611804 926821895 783736508 818928522 190826242 931319426 80143413 88698853...

output:

3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 3734861992 373...

result:

ok single line: '3734861992 3734861992 37348619...09997841 4809997841 4809997841 '

Test #3:

score: 10
Accepted
time: 3ms
memory: 5744kb

input:

10000
56558520 24076 532679989 868659433 718470236 669539219 565891426 405613315 228588763 424940173 86535099 213118975 928296103 44601852 413631070 75973939 166671234 688526244 305448983 282598136 319395657 331028407 440988471 395283245 762047634 431077598 141271074 975860182 295187696 102992550 46...

output:

451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 451500065 ...

result:

ok single line: '451500065 451500065 451500065 ... 452680210 452680210 452680210 '

Test #4:

score: 10
Accepted
time: 12ms
memory: 5740kb

input:

10000
480668445 668043016 295399375 732184676 122324282 255982280 355392797 28731822 344107766 662486064 134432824 995270472 102760799 504208968 650338962 765669861 766398985 162302391 519506962 288925253 28846309 383839304 417396720 407846048 96274977 533045195 127900899 888560800 468796310 3198150...

output:

20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 20741385 207...

result:

ok single line: '20741385 20741385 20741385 207...527 21265527 21265527 21265527 '

Test #5:

score: 10
Accepted
time: 55ms
memory: 16280kb

input:

300000
798955753 286250378 502811779 503621397 92925582 6646849 518944397 770834076 203832545 202893671 103819760 610042299 453933804 743345154 539594131 67829879 56530495 165455177 406676438 149176095 634841263 339856850 623804539 159374193 619691965 719363352 749153472 886061303 174499069 85917864...

output:

65599584 

result:

ok single line: '65599584 '

Test #6:

score: 10
Accepted
time: 93ms
memory: 15764kb

input:

300000
766376442 928503862 759758373 732880914 717705081 564401126 39391912 266563115 890722259 420256593 140756365 543550091 115541768 746823302 612292685 767316055 635845043 654973645 544337001 290376461 576914449 914856675 671199356 713784470 363344552 601573876 31583713 603168080 72489400 375080...

output:

199533222 

result:

ok single line: '199533222 '

Test #7:

score: 10
Accepted
time: 60ms
memory: 17260kb

input:

300000
956686221 414741964 493043893 629807942 180972256 269970594 772545182 612006785 867693543 216559503 730247279 226568318 935026662 707433164 809741369 574785329 807598034 357521029 855386 479475104 141336111 354931933 914443894 54780578 926960727 223607222 373442712 304014927 7965636 516364169...

output:

61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 61009314 610...

result:

ok single line: '61009314 61009314 61009314 610...589 61009589 61009589 61009589 '

Test #8:

score: 10
Accepted
time: 132ms
memory: 16520kb

input:

300000
332562455 457596 240326487 540486075 656909416 733563955 536158780 516014015 725473229 159996733 966117635 384123908 554648950 941913359 735104878 70264708 321207149 649076932 934217283 526740938 203318592 536910059 813024672 584090471 456303660 92830681 922008025 776817225 41208957 906313981...

output:

264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 264657536 ...

result:

ok single line: '264657536 264657536 264657536 ... 264662102 264662102 264662102 '

Test #9:

score: 10
Accepted
time: 117ms
memory: 15732kb

input:

300000
301865399 920265572 576682447 938152861 235472173 759617172 880358770 815285188 557222986 661313551 3537362 758595883 848808290 94541657 186990789 889266656 106528936 255663327 696637470 36185472 196015631 455909180 119220747 337639792 278234577 249069942 500351390 923290017 293186423 3671731...

output:

290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 290501960 ...

result:

ok single line: '290501960 290501960 290501960 ... 290507752 290507752 290507752 '

Test #10:

score: 10
Accepted
time: 76ms
memory: 16900kb

input:

300000
562625121 376819377 685468134 992506922 669101061 952159043 54304806 579126651 572881783 369989807 986688430 603593700 835219329 394853362 13206834 806309995 546320046 681607475 647209229 637169228 918784301 522067469 924188583 892205985 859578401 796516404 614799206 256380193 797680503 70500...

output:

53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 53967000 539...

result:

ok single line: '53967000 53967000 53967000 539...625 53969625 53969625 53969625 '