QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#474105#9120. Huge Segment TreePhantomThreshold#AC ✓522ms100948kbC++173.0kb2024-07-12 16:08:252024-07-12 16:08:25

Judging History

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

  • [2024-07-12 16:08:25]
  • 评测
  • 测评结果:AC
  • 用时:522ms
  • 内存:100948kb
  • [2024-07-12 16:08:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace NTT{
	const int MOD=998244353,g=3,ig=332748118;
	const int MAXN=2777777;
	inline long long poww(long long x,long long y){
		long long ret=1;
		while (y){
			if (y&1) ret*=x,ret%=MOD;
			x*=x,x%=MOD;
			y>>=1;
		}
		return ret;
	}
	inline long long inv(long long x){return poww(x,MOD-2);}
	int R[MAXN];
	inline void fft(vector<long long> &a,int L,int ty){
		for (int i=0;i<L;i++) i>R[i]?swap(a[i],a[R[i]]):void(0);
		for (int i=1;i<L;i<<=1){
			long long w=poww(ty,(MOD-1)/(i<<1));
			for (int j=0;j<L;j+=(i<<1)){
				long long wn=1;
				for (int k=j;k<i+j;k++){
					long long t=wn*a[i+k]%MOD;
					a[i+k]=a[k]-t;a[i+k]<0?a[i+k]+=MOD:0;
					a[k]+=t;a[k]>=MOD?a[k]-=MOD:0;
					wn=wn*w%MOD;	
				}
			}
		}
	}
	inline vector<long long> mul(vector<long long> A,vector<long long> B){
		int L=1,n=A.size()-1,m=B.size()-1;
		while (L<=n+m) L<<=1;
		A.resize(L);
		B.resize(L);
		for (int i=1;i<L;i<<=1)
			for (int j=0;j<i;j++)
				R[i+j]=R[j]+L/(i<<1);
		fft(A,L,g);
		fft(B,L,g);
		vector<long long> ret(L);
		for (int i=0;i<L;i++) ret[i]=A[i]*B[i]%MOD;
		fft(ret,L,ig);
		long long invL=inv(L);
		for (int i=0;i<L;i++) ret[i]=ret[i]*invL%MOD;
		ret.resize(n+m+1);
		return ret;
	}
}

typedef long long ll;

const int maxn=1000000;
const ll mod=998244353;

inline void add(ll &A,ll B){A+=B;if (A>=mod) A-=mod;}
inline void sub(ll &A,ll B){A-=B;if (A<0) A+=mod;}

ll ksm(ll a,ll x){
	ll ret=1;
	for (;x;x>>=1,a=a*a%mod) if (x&1) ret=ret*a%mod;
	return ret;	
}
ll inv(ll a){return ksm(a,mod-2);}

ll fac[maxn+50];
ll ifac[maxn+50];

void prepare(){
	fac[0]=1;
	for (int i=1;i<=maxn;i++) fac[i]=fac[i-1]*i%mod;
	ifac[maxn]=inv(fac[maxn]);
	for (int i=maxn-1;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
//	
//	for (int i=0;i<=10;i++) cout << fac[i] << " ";
//	cout << endl;
//	
//	for (int i=0;i<=10;i++) cout << ifac[i] << " ";
//	cout << endl;
//	
}
ll C(ll n,ll m){
	if (m<0 || m>n) return 0;
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;	
}

ll K=500000;

int main(){
	ios_base::sync_with_stdio(false);
	
	prepare();
	cin >> K;
	
	vector<ll> A(2*K-1);
	vector<ll> ans(2*K-1);
	for (ll c=0;c<=K-1;c++){
		
		ll coef=ksm(2,c);
		ll d=K-1-c;
		
		sub(ans[2],coef);
		add(ans[1],coef);
		
		add(A[2*d],coef);
		add(A[d+1],coef*2%mod);
		sub(A[d],coef*4%mod);
		
		add(A[2],coef);
		sub(A[1],coef*4%mod);
		add(A[0],coef*4%mod);
		
	}
	
	for (ll i=0;i<=2*K-2;i++) A[i]=A[i]*fac[i]%mod;
	
	reverse(A.begin(),A.end());
	vector<ll> tmp(2*K-1);
	for (ll i=0;i<=2*K-2;i++) tmp[i]=ifac[i];
	
	vector<ll> B=NTT::mul(A,tmp);
	B.resize(2*K-1);
	reverse(B.begin(),B.end());
	for (ll i=0;i<=2*K-2;i++) B[i]=B[i]*ifac[i]%mod;
	
//	vector<ll> B(2*K-1);
//	for (int i=0;i<=2*K-2;i++){
//		for (int j=i;j<=2*K-2;j++){
//			add(B[i],A[j]*C(j,i)%mod);
//		}
//	}
	
	for (int i=0;i<=2*K-2;i++) add(ans[i],B[i]);
	add(ans[1],ksm(2,K));
	
	for (int i=1;i<=2*K-2;i++) cout << ans[i] << " \n"[i==2*K-2];
	
	return 0;	
}

详细

Test #1:

score: 100
Accepted
time: 12ms
memory: 19460kb

input:

2

output:

7 3

result:

ok 2 tokens

Test #2:

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

input:

3

output:

15 14 6 1

result:

ok 4 tokens

Test #3:

score: 0
Accepted
time: 7ms
memory: 20232kb

input:

4

output:

31 43 36 19 6 1

result:

ok 6 tokens

Test #4:

score: 0
Accepted
time: 8ms
memory: 19732kb

input:

5

output:

63 110 132 114 70 30 8 1

result:

ok 8 tokens

Test #5:

score: 0
Accepted
time: 12ms
memory: 19744kb

input:

6

output:

127 255 384 448 400 272 136 47 10 1

result:

ok 10 tokens

Test #6:

score: 0
Accepted
time: 8ms
memory: 20728kb

input:

7

output:

255 558 978 1401 1610 1478 1066 589 240 68 12 1

result:

ok 12 tokens

Test #7:

score: 0
Accepted
time: 8ms
memory: 21196kb

input:

8

output:

511 1179 2292 3803 5250 5987 5576 4183 2482 1137 388 93 14 1

result:

ok 14 tokens

Test #8:

score: 0
Accepted
time: 4ms
memory: 19364kb

input:

9

output:

1023 2438 5088 9398 14896 20038 22632 21250 16406 10282 5144 2006 588 122 16 1

result:

ok 16 tokens

Test #9:

score: 0
Accepted
time: 8ms
memory: 20292kb

input:

10

output:

2047 4975 10896 21772 38360 58724 77184 86312 81448 64324 42112 22576 9744 3304 848 155 18 1

result:

ok 18 tokens

Test #10:

score: 0
Accepted
time: 12ms
memory: 20956kb

input:

11

output:

4095 10070 22782 48209 92140 156292 232068 298744 330926 313422 252186 171122 97008 45368 17200 5155 1176 192 20 1

result:

ok 20 tokens

Test #11:

score: 0
Accepted
time: 522ms
memory: 99932kb

input:

500000

output:

390220183 534638705 182393715 303662724 176884209 76063846 314206329 970463075 138271132 869076105 902568877 121426660 599330372 720576343 535733058 609095360 499854676 427738345 789967637 850801793 767689169 103101879 573005863 597231280 725469375 299015007 178535851 966708332 305629 940093777 7830...

result:

ok 999998 tokens

Test #12:

score: 0
Accepted
time: 96ms
memory: 38344kb

input:

72787

output:

863191949 852718765 363831665 964981186 487891193 263854743 37522806 18985671 265243835 698211861 413341848 452649596 684165069 41891590 781946347 633808644 213891845 90859042 654886506 681500079 853399752 536402628 160278411 189221861 144879826 449123001 395247186 477700669 245829076 740028721 3991...

result:

ok 145572 tokens

Test #13:

score: 0
Accepted
time: 36ms
memory: 24060kb

input:

29621

output:

625188972 186328126 837166229 677006047 662339899 556164288 627678499 464879587 574719635 860749906 37224574 952205162 612486418 67731480 127518779 222659320 311864904 739493528 441208728 656349279 675863661 193365665 871786422 429030382 542544944 65332274 279132780 886986640 23673291 260179258 1458...

result:

ok 59240 tokens

Test #14:

score: 0
Accepted
time: 481ms
memory: 90872kb

input:

287834

output:

839249597 106353691 541743754 176289649 331709790 90695814 581166563 660013633 12148749 777570497 239549256 50822832 928845641 783688014 527134794 967565837 8829067 728890387 532021836 723133136 271356603 442733913 109610442 872231778 997519892 627636901 942495046 612005045 480787271 380535891 31598...

result:

ok 575666 tokens

Test #15:

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

input:

372458

output:

238073678 125575487 257781224 432208434 926232022 985032784 972531646 156874450 242230869 958239072 623209641 963804956 760997596 492384034 248852029 480721426 727545366 871518883 526580215 340703419 119254798 894452847 503218079 466661994 21196998 64609258 607451189 866020376 472431142 833623174 95...

result:

ok 744914 tokens

Test #16:

score: 0
Accepted
time: 477ms
memory: 92536kb

input:

326174

output:

182767154 379158505 976650370 950752234 730142912 199366602 217176449 58415818 942059311 29041812 600728528 238722381 35842882 619426938 166582941 887411034 365366704 226747213 653768421 675658473 198607105 971515601 49241364 300610682 741576498 580333820 788122734 812899883 506754294 906735361 8477...

result:

ok 652346 tokens

Test #17:

score: 0
Accepted
time: 506ms
memory: 95708kb

input:

414785

output:

119371452 447324155 812098442 674259707 906095700 995739643 507821850 144836991 944844465 417859866 526136325 446179637 841143258 71594396 600687837 115917880 869472132 733304409 785178785 942797825 461532099 569481220 498200557 562246854 231360418 806781417 603555993 817444062 8765767 415391941 188...

result:

ok 829568 tokens

Test #18:

score: 0
Accepted
time: 51ms
memory: 29460kb

input:

52410

output:

109025791 520279794 997868526 544815757 1210333 262602454 444694081 215482612 359518123 630972106 469202475 93255040 356550496 552798085 978002390 758808807 872405738 26538225 591804454 180245449 487598812 486435998 100463040 636978431 131160375 54547501 21577758 600993423 54379208 278755072 3851668...

result:

ok 104818 tokens

Test #19:

score: 0
Accepted
time: 495ms
memory: 89788kb

input:

266488

output:

670591955 536664499 834582667 435202901 981715449 216606476 24885754 288060317 473842053 728197980 859018006 359189535 188879878 589394421 415307716 612098332 697672094 255330112 873094951 829240529 612715926 251238400 811393752 657428602 471660768 508314629 890321558 248471292 52873644 528909339 36...

result:

ok 532974 tokens

Test #20:

score: 0
Accepted
time: 228ms
memory: 58792kb

input:

235412

output:

838376130 82261816 749813798 853852768 548463514 590159263 767906723 873538508 681808483 793716931 81414518 387819437 489838184 649414809 971267048 518919507 299233671 402683441 670109161 673246099 315748962 982292160 524024775 990312514 930875705 394644470 79309906 651862394 296416662 949936814 511...

result:

ok 470822 tokens

Test #21:

score: 0
Accepted
time: 495ms
memory: 93060kb

input:

335028

output:

412572542 90575816 592590793 134956941 681546461 84123901 23797401 287575357 580630562 822219941 496015371 798714568 996561274 228437956 38964111 210338108 447304705 455001788 541599590 15999929 531678296 86106708 417035208 77019361 258493500 3295255 609295926 388289340 12082287 479955282 13536114 5...

result:

ok 670054 tokens

Test #22:

score: 0
Accepted
time: 496ms
memory: 100876kb

input:

490193

output:

89108812 9400903 759083927 482137918 881472778 819325246 469847190 224397125 941016878 318853318 823063910 192963094 253539854 195834928 305679610 177655853 744021959 486473727 952943524 80929181 726898580 419500987 86904978 500273473 864375683 752394278 447105311 649043680 568500692 716331790 79426...

result:

ok 980384 tokens

Test #23:

score: 0
Accepted
time: 517ms
memory: 100880kb

input:

494427

output:

224396630 171699844 874970651 366738496 188097388 20105024 923005591 475213547 862579354 219327984 402729610 343802472 824016768 274735056 606982614 720737421 379273500 527635893 326566225 588809571 892479263 956818966 119334763 921549067 728518606 341094293 734579914 96978341 54880988 441706555 375...

result:

ok 988852 tokens

Test #24:

score: 0
Accepted
time: 513ms
memory: 100948kb

input:

495456

output:

176309560 31132799 871206936 191727597 372664218 912078745 128667682 749015357 783582110 969205654 792240671 185634038 963924594 739384852 286035580 546230295 777033259 473035706 331715612 919733935 140740960 188303720 108317267 957369642 570466063 215525809 161735173 289750332 41787886 592639789 24...

result:

ok 990910 tokens

Test #25:

score: 0
Accepted
time: 507ms
memory: 100220kb

input:

499498

output:

10762491 87744479 29345176 330762125 67139471 859322674 517319159 444257903 287766504 323230886 614147692 179153449 789116746 632670050 42290946 845385229 648164696 260416611 791349068 162962424 446055973 201137312 796950696 787484329 797523547 634752612 675290933 712512594 448869911 573190874 93885...

result:

ok 998994 tokens

Test #26:

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

input:

493812

output:

613558532 754129691 624537960 491192546 52587972 335888580 918154485 412643191 632432095 756789608 652622556 498719566 684849283 923391920 735537543 543746954 46908287 213544787 692082087 977892286 329586609 673904401 701415241 768595797 918191698 628376968 628786912 839407278 263562545 942236399 70...

result:

ok 987622 tokens

Extra Test:

score: 0
Extra Test Passed