QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305169#8010. Hierarchies of JudgeszhouhuanyiAC ✓2597ms135832kbC++204.6kb2024-01-14 19:48:542024-01-14 19:48:54

Judging History

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

  • [2024-01-14 19:48:54]
  • 评测
  • 测评结果:AC
  • 用时:2597ms
  • 内存:135832kb
  • [2024-01-14 19:48:54]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 200000
#define Z 19
#define M 524288
#define g 3
#define mod 998244353
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int n,sz,length,rev[M+1],num[M+1],fac[N+1],invfac[N+1],inv[N+1],dp[N+1],dp2[N+1],F[N+1],G[N+1],H[N+1],W[N+1],K[N+1],R[N+1],S[N+1],s1[M+1],s2[M+1],s3[M+1],s4[M+1],s5[M+1],s6[M+1],s7[M+1],s8[M+1],s9[M+1],s10[M+1],s11[M+1],s12[M+1],s13[M+1],s14[M+1],s15[M+1],s16[M+1],s17[M+1],s18[M+1],s19[M+1],wn[Z+1][M+1],wn2[Z+1][M+1];
int fast_pow(int a,int b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
void NTT(int limit,int *s,int type)
{
	int s1,s2;
	for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?limit>>1:0);
	for (int i=1;i<limit;++i)
		if (rev[i]>i)
			swap(s[i],s[rev[i]]);
	if (type==1)
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
	}
	else
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn2[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
		s1=fast_pow(limit,mod-2);
		for (int i=0;i<=limit;++i) s[i]=1ll*s[i]*s1%mod;
	}
	return;
}
void solve(int l,int r)
{
	if (l==r)
	{
		Adder(F[l],MD2(W[l-1]-S[l-1])),Adder(G[l],MD2(W[l-1]-K[l-1])),W[l]=1ll*W[l]*inv[l]%mod,K[l]=1ll*K[l]*inv[l]%mod,Adder(W[l],F[l]),Adder(K[l],H[l]),Adder(S[l],R[l]);
		return;
	}
	int mid=(l+r)>>1;
	solve(l,mid);
	int limit=1;
	while (limit<=min(sz,r-l)+mid-l) limit<<=1;
	for (int i=0;i<=limit;++i) s1[i]=s2[i]=s3[i]=s4[i]=s5[i]=s6[i]=s7[i]=s8[i]=s9[i]=s10[i]=s11[i]=s12[i]=s13[i]=s14[i]=0;
	for (int i=l;i<=mid;++i) s1[i-l]=F[i],s2[i-l]=G[i],s3[i-l]=1ll*F[i]*i%mod,s4[i-l]=1ll*H[i]*i%mod,s5[i-l]=W[i],s6[i-l]=K[i],s7[i-l]=R[i];
	for (int i=0;i<=min(sz,r-l);++i) s8[i]=F[i],s9[i]=G[i],s10[i]=1ll*F[i]*i%mod,s11[i]=1ll*H[i]*i%mod,s12[i]=W[i],s13[i]=K[i],s14[i]=R[i];
	NTT(limit,s1,1),NTT(limit,s2,1),NTT(limit,s3,1),NTT(limit,s4,1),NTT(limit,s5,1),NTT(limit,s6,1),NTT(limit,s7,1),NTT(limit,s8,1),NTT(limit,s9,1),NTT(limit,s10,1),NTT(limit,s11,1),NTT(limit,s12,1),NTT(limit,s13,1),NTT(limit,s14,1);
	for (int i=0;i<=limit;++i) s15[i]=MD(1ll*s1[i]*s9[i]%mod+1ll*s8[i]*s2[i]%mod),s16[i]=2ll*s2[i]*s9[i]%mod,s17[i]=MD(1ll*s3[i]*s12[i]%mod+1ll*s10[i]*s5[i]%mod),s18[i]=MD(1ll*s4[i]*s13[i]%mod+1ll*s11[i]*s6[i]%mod),s19[i]=MD(1ll*s6[i]*s14[i]%mod+1ll*s13[i]*s7[i]%mod);
	NTT(limit,s15,-1),NTT(limit,s16,-1),NTT(limit,s17,-1),NTT(limit,s18,-1),NTT(limit,s19,-1);
	for (int i=mid+1;i<=r;++i) Adder(F[i],s15[i-l]),Adder(G[i],s16[i-l]),Adder(H[i],s15[i-l]),Adder(W[i],s17[i-l]),Adder(K[i],s18[i-l]),Adder(R[i],s16[i-l]),Adder(S[i],s19[i-l]);
	solve(mid+1,r);
	return;
}
void calc(int x)
{
	if (x==1)
	{
		F[x]=W[x]=1;
		return;
	}
	int limit=1;
	calc((x+1)>>1);
	while (limit<=x+1) limit<<=1;
	for (int i=0;i<=limit;++i) s1[i]=s2[i]=s3[i]=s4[i]=s5[i]=s6[i]=s7[i]=0;
	for (int i=0;i<=((x+1)>>1);++i) s1[i]=F[i],s2[i]=G[i],s3[i]=1ll*F[i]*i%mod,s4[i]=1ll*H[i]*i%mod,s5[i]=W[i],s6[i]=K[i],s7[i]=R[i];
	NTT(limit,s1,1),NTT(limit,s2,1),NTT(limit,s3,1),NTT(limit,s4,1),NTT(limit,s5,1),NTT(limit,s6,1),NTT(limit,s7,1);
	for (int i=0;i<=limit;++i) s8[i]=1ll*s1[i]*s2[i]%mod,s9[i]=1ll*s2[i]*s2[i]%mod,s10[i]=1ll*s3[i]*s5[i]%mod,s11[i]=1ll*s4[i]*s6[i]%mod,s12[i]=1ll*s6[i]*s7[i]%mod;
	NTT(limit,s8,-1),NTT(limit,s9,-1),NTT(limit,s10,-1),NTT(limit,s11,-1),NTT(limit,s12,-1);
	for (int i=((x+1)>>1)+1;i<=x;++i) Adder(F[i],s8[i]),Adder(G[i],s9[i]),Adder(H[i],s8[i]),Adder(W[i],s10[i]),Adder(K[i],s11[i]),Adder(R[i],s9[i]),Adder(S[i],s12[i]);
	sz=((x+1)>>1),solve(((x+1)>>1)+1,x);
	return;
}
int main()
{
	fac[0]=1;
	for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[N]=fast_pow(fac[N],mod-2);
	for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	for (int i=1;i<=N;++i) inv[i]=1ll*fac[i-1]*invfac[i]%mod;
	for (int i=2,w;i<=M;i<<=1)
	{
		num[i]=++length,w=fast_pow(g,(mod-1)/i);
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn[num[i]][j]=res;
		w=fast_pow(g,(mod-1)/i*(i-1));
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn2[num[i]][j]=res;
	}
	n=read(),calc(n),W[0]=K[0]=1,printf("%lld\n",1ll*MD(F[n]+G[n])*fac[n]%mod);
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 97860kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #3:

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

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #4:

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

input:

100

output:

413875584

result:

ok 1 number(s): "413875584"

Test #5:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

2

output:

4

result:

ok 1 number(s): "4"

Test #7:

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

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #8:

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

input:

4

output:

236

result:

ok 1 number(s): "236"

Test #9:

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

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #10:

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

input:

6

output:

55182

result:

ok 1 number(s): "55182"

Test #11:

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

input:

7

output:

1165220

result:

ok 1 number(s): "1165220"

Test #12:

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

input:

8

output:

29013896

result:

ok 1 number(s): "29013896"

Test #13:

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

input:

9

output:

832517514

result:

ok 1 number(s): "832517514"

Test #14:

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

input:

10

output:

96547079

result:

ok 1 number(s): "96547079"

Test #15:

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

input:

11

output:

296100513

result:

ok 1 number(s): "296100513"

Test #16:

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

input:

12

output:

672446962

result:

ok 1 number(s): "672446962"

Test #17:

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

input:

13

output:

986909297

result:

ok 1 number(s): "986909297"

Test #18:

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

input:

14

output:

306542229

result:

ok 1 number(s): "306542229"

Test #19:

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

input:

15

output:

8548107

result:

ok 1 number(s): "8548107"

Test #20:

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

input:

16

output:

773960239

result:

ok 1 number(s): "773960239"

Test #21:

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

input:

17

output:

611627547

result:

ok 1 number(s): "611627547"

Test #22:

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

input:

18

output:

91793980

result:

ok 1 number(s): "91793980"

Test #23:

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

input:

19

output:

689202618

result:

ok 1 number(s): "689202618"

Test #24:

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

input:

20

output:

605957782

result:

ok 1 number(s): "605957782"

Test #25:

score: 0
Accepted
time: 55ms
memory: 132804kb

input:

10000

output:

713782215

result:

ok 1 number(s): "713782215"

Test #26:

score: 0
Accepted
time: 125ms
memory: 132708kb

input:

20000

output:

337916836

result:

ok 1 number(s): "337916836"

Test #27:

score: 0
Accepted
time: 247ms
memory: 132832kb

input:

30000

output:

580803285

result:

ok 1 number(s): "580803285"

Test #28:

score: 0
Accepted
time: 276ms
memory: 132984kb

input:

40000

output:

732660392

result:

ok 1 number(s): "732660392"

Test #29:

score: 0
Accepted
time: 528ms
memory: 133432kb

input:

50000

output:

660835595

result:

ok 1 number(s): "660835595"

Test #30:

score: 0
Accepted
time: 544ms
memory: 133784kb

input:

60000

output:

323452070

result:

ok 1 number(s): "323452070"

Test #31:

score: 0
Accepted
time: 614ms
memory: 133104kb

input:

70000

output:

307315915

result:

ok 1 number(s): "307315915"

Test #32:

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

input:

80000

output:

951757567

result:

ok 1 number(s): "951757567"

Test #33:

score: 0
Accepted
time: 1082ms
memory: 131692kb

input:

90000

output:

426123208

result:

ok 1 number(s): "426123208"

Test #34:

score: 0
Accepted
time: 1156ms
memory: 131608kb

input:

100000

output:

827418228

result:

ok 1 number(s): "827418228"

Test #35:

score: 0
Accepted
time: 1199ms
memory: 134428kb

input:

110000

output:

541614559

result:

ok 1 number(s): "541614559"

Test #36:

score: 0
Accepted
time: 1220ms
memory: 134156kb

input:

120000

output:

184688986

result:

ok 1 number(s): "184688986"

Test #37:

score: 0
Accepted
time: 1305ms
memory: 135600kb

input:

130000

output:

898089371

result:

ok 1 number(s): "898089371"

Test #38:

score: 0
Accepted
time: 1321ms
memory: 135120kb

input:

140000

output:

949540221

result:

ok 1 number(s): "949540221"

Test #39:

score: 0
Accepted
time: 1349ms
memory: 133876kb

input:

150000

output:

767689851

result:

ok 1 number(s): "767689851"

Test #40:

score: 0
Accepted
time: 1350ms
memory: 135372kb

input:

160000

output:

553494563

result:

ok 1 number(s): "553494563"

Test #41:

score: 0
Accepted
time: 1376ms
memory: 135832kb

input:

170000

output:

270711750

result:

ok 1 number(s): "270711750"

Test #42:

score: 0
Accepted
time: 2465ms
memory: 132756kb

input:

180000

output:

108155689

result:

ok 1 number(s): "108155689"

Test #43:

score: 0
Accepted
time: 2555ms
memory: 132656kb

input:

190000

output:

327542856

result:

ok 1 number(s): "327542856"

Test #44:

score: 0
Accepted
time: 2590ms
memory: 132824kb

input:

200000

output:

236144151

result:

ok 1 number(s): "236144151"

Test #45:

score: 0
Accepted
time: 2597ms
memory: 135752kb

input:

198798

output:

16935264

result:

ok 1 number(s): "16935264"

Extra Test:

score: 0
Extra Test Passed