QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#351114#8329. Excuse275307894aAC ✓153ms15804kbC++143.1kb2024-03-11 15:54:422024-03-11 15:54:42

Judging History

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

  • [2024-03-11 15:54:42]
  • 评测
  • 测评结果:AC
  • 用时:153ms
  • 内存:15804kb
  • [2024-03-11 15:54:42]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=(1<<17)+5,M=(1<<20)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=2e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,k;ll frc[N],inv[N],f[N],g[N],pw[N],iw[N];
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
namespace poly{
	int tr[N];ll pw[N];const int g=3,Ig=mpow(g);
	void init(int n){
		k=0;for(k=1;k<=n;k<<=1);
		for(int i=0;i<k;i++) tr[i]=(tr[i>>1]>>1)|((i&1)?k/2:0);
		ll w=mpow(g,(mod-1)/k);
		pw[k/2]=1;for(int i=k/2+1;i<k;i++) pw[i]=pw[i-1]*w%mod;
		for(int i=k/2-1;i;i--) pw[i]=pw[i<<1];
	}
	void ntt(ll *A,int k,int flag){
		static ull a[N];
		int i,j,h;for(int i=0;i<k;i++) a[tr[i]]=A[i];
		for(int i=2;i<=k;i<<=1){
			ll *e=pw+i/2;
			for(int j=0;j<k;j+=i){
				for(int h=j;h<j+i/2;h++) {
					ll now=e[h-j]*a[h+i/2]%mod;
					a[h+i/2]=a[h]+mod-now;
					a[h]+=now;
				}
			}
		}
		for(int i=0;i<k;i++) A[i]=a[i]%mod;
		if(flag) return;
		ll iv=mpow(k);for(int i=0;i<k;i++) A[i]=A[i]*iv%mod;
		reverse(A+1,A+k);
	}
}
ll A[N],B[N],C[N];
void calc(int l,int r){
	if(l==r) return;int m=l+r>>1;
	calc(l,m);
	poly::init(r-l+3);
	fill(A,A+k,0);fill(B,B+k,0);fill(C,C+k,0);
	for(int i=l;i<=m;i++) A[i-l]=(f[i]+g[i])%mod*iw[n-i]%mod*frc[n-i]%mod,B[i-l]=g[i]*iw[n-i]%mod*frc[n-i]%mod;
	for(int i=1;i<=r-l+1;i++) C[i]=inv[i];
	poly::ntt(A,k,1);poly::ntt(B,k,1);poly::ntt(C,k,1);
	for(int i=0;i<k;i++) A[i]=A[i]*C[i]%mod,B[i]=B[i]*C[i]%mod;
	poly::ntt(A,k,0);poly::ntt(B,k,0);
	for(int i=m+1;i<=r;i++) f[i]=(f[i]+A[i-l]*inv[n-i])%mod,g[i]=(g[i]+B[i-l]*inv[n-i])%mod;
	calc(m+1,r);
}
void Solve(){
	int i,j;scanf("%d",&n);
	inv[1]=1;for(i=2;i<=n;i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
	for(frc[0]=inv[0]=i=1;i<=n;i++) frc[i]=frc[i-1]*i%mod,inv[i]=inv[i]*inv[i-1]%mod;
	for(pw[0]=iw[0]=i=1;i<=n;i++) pw[i]=pw[i-1]*2%mod,iw[i]=iw[i-1]*(mod+1)/2%mod;
	f[0]=0;g[0]=1;calc(0,n);
	/*for(i=1;i<=n;i++){
		for(j=0;j<i;j++) f[i]=(f[i]+(f[j]+g[j])*C(n-j,n-i)%mod*iw[n-j])%mod,g[i]=(g[i]+g[j]*C(n-j,n-i)%mod*iw[n-j])%mod;
	}*/
	ll ans=0;for(i=0;i<=n;i++) ans+=f[i]*iw[n-i]%mod;
	printf("%lld",ans%mod);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12212kb

input:

1

output:

499122177

result:

ok 1 number(s): "499122177"

Test #2:

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

input:

3

output:

561512450

result:

ok 1 number(s): "561512450"

Test #3:

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

input:

10

output:

609769250

result:

ok 1 number(s): "609769250"

Test #4:

score: 0
Accepted
time: 0ms
memory: 12240kb

input:

1000

output:

475714976

result:

ok 1 number(s): "475714976"

Test #5:

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

input:

1024

output:

178624793

result:

ok 1 number(s): "178624793"

Test #6:

score: 0
Accepted
time: 153ms
memory: 15644kb

input:

100000

output:

537516197

result:

ok 1 number(s): "537516197"

Test #7:

score: 0
Accepted
time: 153ms
memory: 15804kb

input:

99471

output:

489775976

result:

ok 1 number(s): "489775976"

Test #8:

score: 0
Accepted
time: 132ms
memory: 15288kb

input:

65536

output:

171446457

result:

ok 1 number(s): "171446457"

Test #9:

score: 0
Accepted
time: 147ms
memory: 15424kb

input:

84792

output:

371578800

result:

ok 1 number(s): "371578800"

Test #10:

score: 0
Accepted
time: 153ms
memory: 15496kb

input:

93846

output:

841905002

result:

ok 1 number(s): "841905002"

Extra Test:

score: 0
Extra Test Passed