QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#352150#8329. Excusegrass8cowAC ✓667ms22536kbC++172.5kb2024-03-12 21:59:472024-03-12 21:59:48

Judging History

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

  • [2024-03-12 21:59:48]
  • 评测
  • 测评结果:AC
  • 用时:667ms
  • 内存:22536kb
  • [2024-03-12 21:59:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,jc[101000],ij[101000],p2[100100],i2[100100];
const int mod=998244353,G=3,GI=(mod+1)/3,inv2=(mod+1)/2;
int qpow(int a,ll b){
	int c=1;
	for(;b;b>>=1){
		if(b&1)c=1ll*a*c%mod;
		a=1ll*a*a%mod; 
	}
	return c;
}
int lb[1<<20],L;
void init(int n){
	L=1;while(L<=n)L<<=1;
	for(int i=0;i<L;i++)lb[i]=(lb[i>>1]>>1)|((i&1)?(L>>1):0);
}
void NTT(int *a,int fl){
	for(int i=0;i<L;i++)if(i<lb[i])swap(a[i],a[lb[i]]);
	for(int o=1;o<L;o<<=1){
		int Wn=qpow(fl?G:GI,(mod-1)/(o<<1));
		for(int i=0;i<L;i+=(o<<1))for(int j=0,w=1;j<o;j++,w=1ll*w*Wn%mod){
			int x=a[i+j],y=1ll*a[i+j+o]*w%mod;
			a[i+j]=(x+y)%mod,a[i+j+o]=(x-y)%mod;
		}
	}
	if(!fl){
		int I=qpow(L,mod-2);
		for(int i=0;i<L;i++)a[i]=1ll*a[i]*I%mod; 
	}
}
int fz1[1<<20],fz2[1<<20];
void Inv(int *a,int *b,int n){
	if(n==1){b[0]=qpow(a[0],mod-2);return;}
	int N=(n+1)>>1;Inv(a,b,N);
	init(2*n+5);
	for(int i=0;i<L;i++)fz1[i]=0;
	for(int i=0;i<n;i++)fz1[i]=a[i];
	for(int i=N;i<L;i++)b[i]=0;
	NTT(fz1,1),NTT(b,1);
	for(int i=0;i<L;i++)fz1[i]=1ll*b[i]*(2-1ll*b[i]*fz1[i]%mod)%mod;
	NTT(fz1,0);
	for(int i=0;i<n;i++)b[i]=fz1[i];
}
int g[100010],g_[1<<20],a[100100],P2[101000];
void cdq(int l,int r){
	if(l==r){
		if(l>0)g[l]=1ll*g[l]*i2[l]%mod*qpow(1-i2[l],mod-2)%mod;
		return;
	}
	int mid=(l+r)>>1;
	cdq(l,mid);
	init((r-l+1)*2);
	for(int i=0;i<L;i++)fz1[i]=fz2[i]=0;
	for(int i=0;i<=mid-l;i++)fz1[i]=g[i+l];
	for(int i=1;i<=r-l;i++)fz2[i]=ij[i+1];
	NTT(fz1,1),NTT(fz2,1); 
	for(int i=0;i<L;i++)fz1[i]=1ll*fz1[i]*fz2[i]%mod;
	NTT(fz1,0);
	for(int i=mid+1;i<=r;i++)(g[i]+=fz1[i-l])%=mod;
	cdq(mid+1,r);
}
int main(){
	scanf("%d",&n);
	jc[0]=ij[0]=p2[0]=i2[0]=P2[0]=1;
	for(int i=1;i<=n+1;i++)jc[i]=1ll*i*jc[i-1]%mod,ij[i]=qpow(jc[i],mod-2),p2[i]=2*p2[i-1]%mod,i2[i]=1ll*inv2*i2[i-1]%mod,
	P2[i]=1ll*P2[i-1]*p2[i]%mod;
	//g(x)=f(x/2)g(x/2)
	//g_i=2^_{-i}*sum f_ig_{x-i}
	g[0]=1;
	cdq(0,n);
	/*for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++)(g[i]+=1ll*g[i-j]*f[j]%mod)%=mod;
		g[i]=1ll*g[i]*i2[i]%mod*qpow(1-i2[i],mod-2)%mod;
	}*/
	Inv(g,g_,n+1);
	init(n*2+3);for(int i=n+1;i<L;i++)g_[i]=0;
	memset(fz1,0,sizeof(fz1)); 
	for(int i=0;i<=n;i++)fz1[i]=ij[i];
	NTT(g_,1),NTT(fz1,1);for(int i=0;i<L;i++)g_[i]=1ll*g_[i]*fz1[i]%mod;
	NTT(g_,0);
	for(int i=0;i<=n;i++)g_[i]=1ll*g_[i]*P2[i]%mod;
	for(int i=0,s=0;i<=n;i++)a[i]=1ll*s*qpow(P2[i],mod-2)%mod,(s+=g_[i])%=mod;
	int ans=0;
	for(int i=0;i<=n;i++)(ans+=1ll*a[i]*g[n-i]%mod)%=mod;
	return printf("%d",(1ll*ans*jc[n]%mod+mod)%mod),0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 14004kb

input:

1

output:

499122177

result:

ok 1 number(s): "499122177"

Test #2:

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

input:

3

output:

561512450

result:

ok 1 number(s): "561512450"

Test #3:

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

input:

10

output:

609769250

result:

ok 1 number(s): "609769250"

Test #4:

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

input:

1000

output:

475714976

result:

ok 1 number(s): "475714976"

Test #5:

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

input:

1024

output:

178624793

result:

ok 1 number(s): "178624793"

Test #6:

score: 0
Accepted
time: 667ms
memory: 20812kb

input:

100000

output:

537516197

result:

ok 1 number(s): "537516197"

Test #7:

score: 0
Accepted
time: 660ms
memory: 20900kb

input:

99471

output:

489775976

result:

ok 1 number(s): "489775976"

Test #8:

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

input:

65536

output:

171446457

result:

ok 1 number(s): "171446457"

Test #9:

score: 0
Accepted
time: 636ms
memory: 22536kb

input:

84792

output:

371578800

result:

ok 1 number(s): "371578800"

Test #10:

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

input:

93846

output:

841905002

result:

ok 1 number(s): "841905002"

Extra Test:

score: 0
Extra Test Passed