QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810938#9651. 又一个欧拉数问题_lbw_100 ✓894ms105812kbC++176.3kb2024-12-12 13:37:542024-12-12 13:37:56

Judging History

This is the latest submission verdict.

  • [2024-12-12 13:37:56]
  • Judged
  • Verdict: 100
  • Time: 894ms
  • Memory: 105812kb
  • [2024-12-12 13:37:54]
  • Submitted

answer

#define G 3
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<bitset>
#include<cstdio>
#include<vector>
#include<random>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
#define I ll
#define her1 20081214
#define IV void
#define cht 998244353
#define ld long double
#define Aestas16 392699
#define ull unsigned long long
#define cp(x,y)memcpy(x,y,sizeof y)
#define mem(x,val)memset(x,val,sizeof x)
#define D(i,j,n)for(register int i=j;i>=n;i--)
#define E(i,now)for(register int i=first[now];i;i=e[i].nxt)
#define F(i,j,n)for(register int i=j;i<=n;i++)
#define DL(i,j,n)for(register i64 i=j;i>=n;i--)
#define EL(i,now)for(register i64 i=first[now];i;i=e[i].nxt)
#define FL(i,j,n)for(register i64 i=j;i<=n;i++)
//#define D(i,j,n)for(int i=j;i>=n;i--)
//#define E(i,now)for(int i=first[now];i;i=e[i].nxt)
//#define F(i,j,n)for(int i=j;i<=n;i++)
//#define DL(i,j,n)for(register ll i=j;i>=n;i--)
//#define EL(i,now)for(register ll i=first[now];i;i=e[i].nxt)
//#define FL(i,j,n)for(register ll i=j;i<=n;i++)
ll read(){
	ll ans=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')ans=ans*10+c-'0',c=getchar();
	return ans*f;
}
#undef ll
#include "assert.h"
mt19937_64 rnd(her1);
#include "functional"
using i64 = long long;
const int MAX = 2e5;
const int maxn = 2e5+5;
const int maxm = 6e5+5;
#define in(i,V) F(i,0,(i64)V.size()-1)
#define My_assert(expr,tips) ((expr)?(void(0)):(puts(tips),exit(0)))
IV cadd(i64&x,i64 val){x=(x+val)%cht;}

i64 w[maxm];
i64 qpow(i64 n,i64 base=cht-2){
	i64 ans=1;
	while(base){
		if(base&1)ans=ans*n%cht;
		n=n*n%cht;base>>=1;
	}
	return ans;
}
IV init(i64 limit){
	for(int i=1,j,k;i<limit;i<<=1)
		for(w[j=i]=1,k=qpow(3,(cht-1)/(i<<1)),j++;j<(i<<1);j++)
			w[j]=w[j-1]*k%cht;
}
const i64 invG = qpow(G);
IV DIT(i64*a,i64 limit){
	for(i64 i,j,k=limit>>1,L,*W,*x,*y,z;k;k>>=1)
		for(L=k<<1,i=0;i<limit;i+=L)for(j=0,W=w+k,x=a+i,y=x+k;j<k;j++,W++,x++,y++)
			*y=(*x+cht-(z=*y))* *W%cht,*x=(*x+z)%cht;
}
IV DIF(i64*a,i64 limit){
	for(i64 i,j,k=1,L,*W,*x,*y,z;k<limit;k<<=1)
		for(L=k<<1,i=0;i<limit;i+=L)for(j=0,W=w+k,x=a+i,y=x+k;j<k;j++,W++,x++,y++)
			z=1ll* *W* *y%cht,*y=(*x-z)%cht,*x=(*x+z)%cht;
	reverse(a+1,a+limit);
	i64 inv=qpow(limit);
	F(i,0,limit-1)a[i]=a[i]*inv%cht;
}
IV NTT(i64*a,i64 limit,i64 type){
	static i64 rev[maxm];
	i64 sb=__lg(limit);
	F(i,0,limit-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<sb-1);
	F(i,0,limit-1)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int p=2;p<=limit;p<<=1){
		i64 wG=qpow(type?invG:G,(cht-1)/p),k=(p>>1);
		for(i64 l=0,w=1;l<limit;l+=p,w=1)F(i,l,l+k-1){
			i64 x=a[i],y=a[i+k]*w%cht;
			a[i]=(x+y)%cht;a[i+k]=(x-y+cht)%cht;w=w*wG%cht;
		}
	}
	if(type){
		i64 inv=qpow(limit);
		F(i,0,limit-1)a[i]=a[i]*inv%cht;
	}
}
#define poly vector<i64>

poly operator*(const poly&A,const poly&B){
	static i64 f[maxm],g[maxm];
	My_assert(A.size()&&B.size(),"multiply with a empty poly.");
	i64 limit=1;
	while(limit<=A.size()+B.size())
		limit<<=1;
	F(i,0,limit-1)f[i]=g[i]=0;
	in(i,A)f[i]=A[i];in(i,B)g[i]=B[i];
	DIT(f,limit);DIT(g,limit);
	F(i,0,limit-1)f[i]=f[i]*g[i]%cht;DIF(f,limit);
	poly C;C.resize(A.size()+B.size()-1);
	in(i,C)C[i]=f[i];
	return C;
}
poly operator+(const poly&A,const poly&B){
	poly C;C.resize(max(A.size(),B.size()));
	in(i,C)C[i]=0;
	in(i,A)cadd(C[i],A[i]);
	in(i,B)cadd(C[i],B[i]);
	return C;
}
poly operator-(const poly&A,const poly&B){
	poly C;C.resize(max(A.size(),B.size()));
	in(i,C)C[i]=0;
	in(i,A)cadd(C[i],A[i]);
	in(i,B)cadd(C[i],-B[i]);
	return C;
}

i64 fac[maxn],ifac[maxn];
i64 C(i64 n,i64 m){
	if(n<m||n<0||m<0)return 0;
	return fac[n]*ifac[m]%cht*ifac[n-m]%cht;
}
IV init(){
	fac[0]=1;F(i,1,MAX)fac[i]=fac[i-1]*i%cht;
	ifac[MAX]=qpow(fac[MAX]);D(i,MAX-1,0)ifac[i]=ifac[i+1]*(i+1)%cht;
}
IV remod(poly&A,i64 n){while(A.size()>n)A.pop_back();}

i64 n,k,wi[1<<3],S,f[maxn][4];
i64 upd(i64 z,i64 x){return(z|x<<k-2)>>1;}
i64 c[4][4][1<<18],c2[4][4][1<<19];
i64 sv[4][1<<18];
IV cdq(i64 l,i64 r){
	if(l==r)return;i64 mid=l+r>>1;
	cdq(l,mid);

	i64 L=1;while(L<=(r-l)*2)L<<=1;
	F(x,0,S)F(i,0,L-1)sv[x][i]=0;
	// puts("??");
	F(x,0,S){
		static i64 a[1<<18];
		F(i,0,L-1)a[i]=0;F(i,l,mid)a[i-l]=f[i][x];
		DIT(a,L);
		// if(l==2&&r==6){
		// 	F(i,0,L-1)cout<<a[i]<<' ';puts("");
		// 	F(i,0,L-1)cout<<c2[x][0][L+i]<<' ';puts("");
		// }
		F(y,0,S)F(i,0,L-1)cadd(sv[y][i],c2[x][y][L+i]*a[i]);
	}
	// cout<<l<<' '<<mid<<' '<<r<<endl;
	// F(x,0,S){
	// 	F(i,0,L-1)cout<<sv[x][i]<<' ';puts("");
	// }
	F(x,0,S)DIF(sv[x],L);
	// F(x,0,S){
	// 	F(i,0,L-1)cout<<sv[x][i]<<' ';puts("");
	// }
	F(i,mid+1,r)F(x,0,S)
		cadd(f[i][x],sv[x][i-l]);

	cdq(mid+1,r);
}
int main(){
	// freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout);

	init();init(1<<18);
	n=read();k=read();S=(1<<k-2)-1;
	F(s,0,S*2+1)wi[s]=read();f[0][0]=1;
	F(i,0,k-1){
		F(s,0,S)if(f[i][s]){
			i64 tmp[4];mem(tmp,0);
			tmp[upd(s,0)]=f[i][s]*(i+1>=k?wi[s]:1)%cht;
				// F(z,0,S)cout<<tmp[z]<<' ';puts("");
			F(j,i+1,n){
				F(z,0,S)cadd(f[j][z],tmp[z]*ifac[j-i]);
				i64 ntmp[4];mem(ntmp,0);
				F(z,0,S){
					cadd(ntmp[upd(z,0)],-tmp[z]*(j+1>=k?wi[z]:1));
					cadd(ntmp[upd(z,1)],tmp[z]*(j+1>=k?wi[z|(1<<k-2)]:1));
					// cout<<(z|(1<<k-2))<<' '<<wi[z|(1<<k-2)]<<endl;
				}
				F(z,0,S)tmp[z]=ntmp[z];
			}
		}
	}
	// F(i,0,n)
	// F(s,0,S)if(f[i][s]){
	// 	cout<<i<<' '<<s<<' '<<f[i][s]<<endl;
	// }
	F(s,0,S){
		i64 tmp[4];mem(tmp,0);tmp[upd(s,0)]=wi[s];
		F(i,1,n){
			F(z,0,S)cadd(c[s][z][i],tmp[z]*ifac[i]);
			i64 ntmp[4];mem(ntmp,0);
			F(z,0,S){
				cadd(ntmp[upd(z,0)],-tmp[z]*wi[z]);
				cadd(ntmp[upd(z,1)],tmp[z]*wi[z|(1<<k-2)]);
			}
			F(z,0,S)tmp[z]=ntmp[z];
		}
	}
	// F(i,1,n)cout<<c[0][0][i]<<' ';puts("");
	F(x,0,S)F(y,0,S)for(int L=2;L<=4*(n+1);L<<=1){
		static i64 T[maxn];
		F(i,0,L-1)T[i]=c[x][y][i];DIT(T,L);
		F(i,0,L-1)c2[x][y][L+i]=T[i];
		// cout<<"?"<<L<<endl;
		// F(i,0,L-1)cout<<T[i]<<' ';puts("");
	}
	// F(i,0,100)cout<<c2[0][0][i]<<' ';puts("");
	cdq(k,n);
	// F(i,0,n)
	// F(s,0,S)if(f[i][s]){
	// 	cout<<i<<' '<<s<<' '<<f[i][s]<<endl;
	// }
	i64 Ans=0;F(z,0,S)cadd(Ans,f[n][z]);
	cout<<(Ans*fac[n]%cht+cht)%cht;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 48720kb

input:

4 4
698120943 122288832 680575548 463848799 156774757 854895700 608223343 677744207

output:

129451994

result:

ok 1 number(s): "129451994"

Test #2:

score: 5
Accepted
time: 4ms
memory: 57080kb

input:

5 4
550891357 916542306 749948554 123704496 62951279 389103312 185283715 952036050

output:

603530316

result:

ok 1 number(s): "603530316"

Test #3:

score: 5
Accepted
time: 0ms
memory: 56924kb

input:

5 4
0 0 0 0 0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 5
Accepted
time: 6ms
memory: 56920kb

input:

9 4
932794876 983187846 61110015 10089567 242406926 990649413 302889463 707289292

output:

623984278

result:

ok 1 number(s): "623984278"

Test #5:

score: 5
Accepted
time: 4ms
memory: 54868kb

input:

10 4
0 0 0 0 0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 5
Accepted
time: 0ms
memory: 55028kb

input:

7 4
75656923 89231235 268411832 331473274 613621490 724088841 938061331 436247598

output:

828280933

result:

ok 1 number(s): "828280933"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #7:

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

input:

17 4
502378168 0 899256313 98988040 502378168 899256313 495866185 403390128

output:

955634034

result:

ok 1 number(s): "955634034"

Test #8:

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

input:

12 4
973896694 511296006 0 486948347 0 0 486948347 511296006

output:

717853738

result:

ok 1 number(s): "717853738"

Test #9:

score: 10
Accepted
time: 4ms
memory: 55092kb

input:

19 4
0 0 0 0 0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 10
Accepted
time: 4ms
memory: 56824kb

input:

11 4
419369069 674825741 201692543 290396938 869076983 225876646 409445596 934556751

output:

579300967

result:

ok 1 number(s): "579300967"

Test #11:

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

input:

16 4
399991278 671519396 535203044 718737955 71028311 806731162 326724957 940847965

output:

842945071

result:

ok 1 number(s): "842945071"

Test #12:

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

input:

17 4
836771329 338008804 131570815 515413785 262236691 408466186 362787701 152542617

output:

293433305

result:

ok 1 number(s): "293433305"

Subtask #3:

score: 5
Accepted

Test #13:

score: 5
Accepted
time: 6ms
memory: 17888kb

input:

2 2
0 0

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 5
Accepted
time: 5ms
memory: 15896kb

input:

3 2
0 142044554

output:

704013496

result:

ok 1 number(s): "704013496"

Test #15:

score: 5
Accepted
time: 5ms
memory: 15800kb

input:

4 2
0 0

output:

0

result:

ok 1 number(s): "0"

Test #16:

score: 5
Accepted
time: 0ms
memory: 19992kb

input:

5 2
0 0

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 5
Accepted
time: 171ms
memory: 27984kb

input:

99487 2
0 0

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 5
Accepted
time: 166ms
memory: 27976kb

input:

99738 2
693173587 283412622

output:

815899210

result:

ok 1 number(s): "815899210"

Subtask #4:

score: 10
Accepted

Test #19:

score: 10
Accepted
time: 6ms
memory: 22048kb

input:

3 3
977925087 204858071 813705548 204858071

output:

225177337

result:

ok 1 number(s): "225177337"

Test #20:

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

input:

4 3
455457192 542787161 728591379 0

output:

494572650

result:

ok 1 number(s): "494572650"

Test #21:

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

input:

5 3
280102847 175353772 822890581 718141506

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

93 3
517938077 480306276 173009841 0

output:

132737095

result:

ok 1 number(s): "132737095"

Test #23:

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

input:

85 3
812966373 8069068 241411799 241442405

output:

835292882

result:

ok 1 number(s): "835292882"

Test #24:

score: 10
Accepted
time: 4ms
memory: 28196kb

input:

93 3
740309863 562024812 723775833 67304547

output:

79626905

result:

ok 1 number(s): "79626905"

Subtask #5:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #25:

score: 10
Accepted
time: 7ms
memory: 28584kb

input:

3204 3
390926493 321900190 164112702 172373440

output:

25228045

result:

ok 1 number(s): "25228045"

Test #26:

score: 10
Accepted
time: 7ms
memory: 28080kb

input:

118 3
0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #27:

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

input:

1812 3
743708154 0 458364972 539879381

output:

369996118

result:

ok 1 number(s): "369996118"

Test #28:

score: 10
Accepted
time: 11ms
memory: 28536kb

input:

3997 3
506494422 310846999 0 0

output:

180977771

result:

ok 1 number(s): "180977771"

Test #29:

score: 10
Accepted
time: 7ms
memory: 28608kb

input:

3919 3
850826367 581870616 262788170 385598679

output:

718155036

result:

ok 1 number(s): "718155036"

Test #30:

score: 10
Accepted
time: 9ms
memory: 24248kb

input:

3908 3
268833736 15860337 13324648 101653332

output:

307317750

result:

ok 1 number(s): "307317750"

Subtask #6:

score: 15
Accepted

Dependency #5:

100%
Accepted

Test #31:

score: 15
Accepted
time: 73ms
memory: 38320kb

input:

27617 3
649538421 649538421 697411864 348705932

output:

147599656

result:

ok 1 number(s): "147599656"

Test #32:

score: 15
Accepted
time: 68ms
memory: 38276kb

input:

32594 3
0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #33:

score: 15
Accepted
time: 73ms
memory: 27224kb

input:

18203 3
971232001 436685091 53582375 579077060

output:

15944343

result:

ok 1 number(s): "15944343"

Test #34:

score: 15
Accepted
time: 162ms
memory: 36576kb

input:

39024 3
761026701 107837672 107837672 129379980

output:

733762036

result:

ok 1 number(s): "733762036"

Test #35:

score: 15
Accepted
time: 151ms
memory: 38600kb

input:

39934 3
860432642 218393709 0 137811711

output:

959310258

result:

ok 1 number(s): "959310258"

Test #36:

score: 15
Accepted
time: 159ms
memory: 40876kb

input:

39441 3
647870660 428771613 299764381 537645434

output:

403002156

result:

ok 1 number(s): "403002156"

Subtask #7:

score: 5
Accepted

Dependency #6:

100%
Accepted

Test #37:

score: 5
Accepted
time: 324ms
memory: 46640kb

input:

65961 3
573372243 470586592 899656037 952529871

output:

727883299

result:

ok 1 number(s): "727883299"

Test #38:

score: 5
Accepted
time: 369ms
memory: 50508kb

input:

95856 3
657353865 0 340890488 0

output:

443504623

result:

ok 1 number(s): "443504623"

Test #39:

score: 5
Accepted
time: 162ms
memory: 41128kb

input:

43044 3
735177548 164240636 263066805 263066805

output:

357165044

result:

ok 1 number(s): "357165044"

Test #40:

score: 5
Accepted
time: 368ms
memory: 50644kb

input:

99124 3
0 626743689 688853562 309390791

output:

488790683

result:

ok 1 number(s): "488790683"

Test #41:

score: 5
Accepted
time: 369ms
memory: 49000kb

input:

99895 3
599127905 0 269443581 399116448

output:

308060904

result:

ok 1 number(s): "308060904"

Test #42:

score: 5
Accepted
time: 368ms
memory: 50764kb

input:

99441 3
81228584 583326742 103263243 128429203

output:

142331215

result:

ok 1 number(s): "142331215"

Subtask #8:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #43:

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

input:

4 4
0 0 0 0 0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #44:

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

input:

5 4
719850794 868458999 534771757 496641034 108328567 58126453 451622145 127965210

output:

199502123

result:

ok 1 number(s): "199502123"

Test #45:

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

input:

1620 4
575012072 993907457 465640749 414558489 536940500 884536134 536940500 579348968

output:

276727543

result:

ok 1 number(s): "276727543"

Test #46:

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

input:

2000 4
583522935 653359292 238637874 720209712 120795105 906170921 202280741 436530633

output:

247950749

result:

ok 1 number(s): "247950749"

Test #47:

score: 10
Accepted
time: 16ms
memory: 57304kb

input:

1903 4
0 0 0 0 0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #48:

score: 10
Accepted
time: 7ms
memory: 57020kb

input:

1970 4
634852705 681848099 480528749 96325370 426074420 662814695 282626889 407588785

output:

358841946

result:

ok 1 number(s): "358841946"

Subtask #9:

score: 10
Accepted

Dependency #8:

100%
Accepted

Test #49:

score: 10
Accepted
time: 371ms
memory: 95444kb

input:

35788 4
137592553 167362125 666174864 893867308 935259273 409053348 908484962 421828880

output:

317183526

result:

ok 1 number(s): "317183526"

Test #50:

score: 10
Accepted
time: 89ms
memory: 89608kb

input:

13180 4
455644004 629655674 433939914 99482062 167912374 215744296 744048010 856909532

output:

724269763

result:

ok 1 number(s): "724269763"

Test #51:

score: 10
Accepted
time: 193ms
memory: 93336kb

input:

25810 4
50511582 266090813 782665122 316602395 681641958 25053907 922678864 732153540

output:

316456760

result:

ok 1 number(s): "316456760"

Test #52:

score: 10
Accepted
time: 379ms
memory: 93596kb

input:

39626 4
0 0 0 0 0 0 0 0

output:

0

result:

ok 1 number(s): "0"

Test #53:

score: 10
Accepted
time: 387ms
memory: 93512kb

input:

39520 4
304751689 247786932 175360249 662006566 300713484 967876352 912150432 961654612

output:

581564252

result:

ok 1 number(s): "581564252"

Test #54:

score: 10
Accepted
time: 380ms
memory: 93756kb

input:

39654 4
199691859 32920622 161790938 562758769 16726982 895821371 135168521 518536619

output:

389091873

result:

ok 1 number(s): "389091873"

Subtask #10:

score: 20
Accepted

Dependency #9:

100%
Accepted

Test #55:

score: 20
Accepted
time: 816ms
memory: 101564kb

input:

70610 4
68292738 168290466 829953887 829953887 168290466 929951615 99997728 829953887

output:

139356701

result:

ok 1 number(s): "139356701"

Test #56:

score: 20
Accepted
time: 880ms
memory: 105812kb

input:

83154 4
40222982 0 40222982 40222982 958021371 0 877575407 0

output:

810635777

result:

ok 1 number(s): "810635777"

Test #57:

score: 20
Accepted
time: 402ms
memory: 99488kb

input:

50832 4
105333371 857557033 892910982 260281951 843295773 154948580 892910982 892910982

output:

241653357

result:

ok 1 number(s): "241653357"

Test #58:

score: 20
Accepted
time: 894ms
memory: 105080kb

input:

99201 4
259092713 0 0 811163900 446173166 552071187 739151640 187080453

output:

150187101

result:

ok 1 number(s): "150187101"

Test #59:

score: 20
Accepted
time: 891ms
memory: 103676kb

input:

99797 4
367311954 251136106 555832002 724805462 945161134 244359464 684015618 92172056

output:

25758638

result:

ok 1 number(s): "25758638"

Test #60:

score: 20
Accepted
time: 889ms
memory: 103804kb

input:

99065 4
671004682 687177570 888521328 363461538 143576590 52815535 910840671 989086834

output:

379711332

result:

ok 1 number(s): "379711332"