QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307332#8010. Hierarchies of Judgesucup-team918AC ✓5498ms58024kbC++1710.0kb2024-01-18 14:12:342024-01-18 14:12:35

Judging History

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

  • [2024-01-18 14:12:35]
  • 评测
  • 测评结果:AC
  • 用时:5498ms
  • 内存:58024kb
  • [2024-01-18 14:12:34]
  • 提交

answer

/* Code by pp_orange */
//#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
#define m_p(a,b) make_pair(a,b)
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 0x7FFFFFFF
#define inff 9223372036854775807
#define rep(i,l,r) for(int i=l;i<r;++i)
#define repp(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r-1;i>=l;--i)
#define pper(i,r,l) for(int i=r;i>=l;--i)
#define pii pair<int,int>
#define fi first
#define se second
#define p_q priority_queue
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
#define lb(x) ((x)&-(x))
#define lg(x) (31^__builtin_clz(x))
#define vi vector<int>
#define vii vector<pii >
const int mod = 998244353;
//#define int ll
const int intsz = sizeof(int);
using namespace std;
inline int rd(){
	int x(0),f(1);char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while (isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
inline void out(int X){
	if(X<0) {X=~(X-1); putchar('-');}
	if(X>9) out(X/10);
	putchar(X%10+'0');
}
ll pw(ll x,int d){
	ll t = 1;
	for(;d;d>>=1,x=x*x%mod)if(d&1)t = t*x%mod;
	return t;
}
#define MAX (1<<19)
// const int Gs[20] = ;
namespace poly{
	#define CTZ __builtin_ctz
	const int de = 1;
	const int G = 3;
	const int Gi = pw(G,mod-2);
	typedef complex<ld> cplx;
	const ld pi = acos(-1);
	int getN(int n){
		int N = 1;
		while(N<=n)N<<=1;
		return N;
	}
	namespace polyTrs{
		int r[MAX];
		int nwsz = -1;
		void initR(int N,int lim){
			if(nwsz==lim)return ;
			nwsz = lim;
			rep(i,1,N)r[i] = (r[i>>1]>>1)|((i&1)<<(lim-1));
			return ;
		}
		
		void NTT(int *a,int N,int tp){
		//1:G, -1:Gi
		//need init R
			int x,y;
			const int g = tp==1?G:Gi;
			int omg;
			ll w;
			rep(i,0,N)if(r[i]<i)swap(a[i],a[r[i]]);
			for(int mid=1;mid<N;(mid<<=1)){
				omg = pw(g,(mod-1)/(mid<<1));
				for(int i=0,len=(mid<<1);i<N;i+=len){
					w = 1;
					for(int j=i;j<i+mid;++j,w=w*omg%mod){
						x = a[j];
						y = a[j+mid]*w%mod;
						a[j] = x+y;
						if(a[j]>=mod)a[j] -= mod;
						a[j+mid] = x-y;
						if(a[j+mid]<0)a[j+mid] += mod;
					}
				}
			}
			return ;
		}
	}using polyTrs::NTT,polyTrs::initR;
	
	namespace polyMul{
		int tmp[MAX];
		void Mul(int *a,int n,int *b,int m){
		//Mul(rlt,n,b,m) , won't destroy b
		//a^n and b^m
			memcpy(tmp,b,intsz*(m+1));
			int lim = 0;
			int N = 1;
			while(N<=n+m){
				N <<= 1;
				lim++;
			}
			initR(N,lim);
			NTT(a,N,1);
			NTT(b,N,1);
			ll Ni = pw(N,mod-2);
			rep(i,0,N)a[i] = (ll)a[i]*b[i]%mod*Ni%mod;
			NTT(a,N,-1);
			memcpy(b,tmp,intsz*(m+1));
			//rep(i,0,N)cout<<tmp[i]<<',';cout<<endl;
			memset(b+m+1,0,intsz*(N-(m+1)));
			return ;
		}
	}using polyMul::Mul;
	
	
	void Inv(int *b,int *a,int n){
	//Inv(output,input,n) mod x^n , won't destroy a
	//safe for *b
		static int f[MAX];
		if(de)assert(a[0]!=0);
		int N = 1;
		int lim = 0;
		b[0] = pw(a[0],mod-2);b[1] = 0;
		while(N<n){
			lim++;
			N <<= 1;
			memset(b+N,0,intsz*N);
			memcpy(f,a,intsz*N);
			memset(f+N,0,intsz*N);
			initR(N<<1,lim+1);
			NTT(b,N*2,1);
			NTT(f,N*2,1);
			rep(i,0,N*2)f[i] = b[i]*(2-(ll)b[i]*f[i]%mod+mod)%mod;
			NTT(f,N*2,-1);
			ll Ni = pw(N*2,mod-2);
			rep(i,0,N)b[i] = f[i]*Ni%mod;
			memset(b+N,0,intsz*N);
		}
		memset(b+n,0,intsz*(N-n));
	}
	void Sqrt(int *b,int *a,int n){
	//Sqrt(output,input,n) , mod x^n
		static int gi[MAX];
		static int f[MAX];
		static const int inv2 = pw(2,mod-2);
		int N = 1;
		int lim = 0;
		if(de)assert(a[0]==1);
		b[0] = 1;b[1] = 0;
		while(N<n){
			lim++;
			N <<= 1;
			memset(b+N,0,intsz*N);
			Inv(gi,b,N);
			memset(gi+N,0,intsz*N);
			memcpy(f,a,intsz*N);
			memset(f+N,0,intsz*N);
			initR(N*2,lim+1);
			NTT(gi,N*2,1);
			NTT(f,N*2,1);
			NTT(b,N*2,1);
			ll Ni = pw(N*2,mod-2);
			rep(i,0,N*2)b[i] = ((ll)f[i]*gi[i]%mod+b[i])*inv2%mod*Ni%mod;
			NTT(b,N*2,-1);
			memset(b+N,0,intsz*N);
		}
		memset(b+n,0,intsz*(N-n));
		return ;
	}
	
	void Dev(int *a,int n){
	//get Dev [ 0 , n )
		rep(i,0,n-1)a[i] = ((ll)a[i+1]*(i+1))%mod;
		a[n-1] = 0;
		return ;
	}
	
	namespace polyInter{
		int inv[MAX] = {0,1};
		int invsz = 1;
		void initInv(int sz){
			if(sz<=invsz)return ;
			repp(i,2,sz)inv[i] = (mod-(ll)inv[mod%i]*(mod/i)%mod);
			invsz = sz;
		}
		void Inter(int *a,int n){
		//get Inter [ 0 , n )
			initInv(n);
			per(i,n,1)a[i] = ((ll)a[i-1]*inv[i])%mod;
			a[0] = 0;
			return ;
		}
	}using polyInter::Inter;
	
	void Ln(int *b,int *a,int n){
	//Ln(out,in,n) , won't destroy a , mod x^n
		static int tmp[MAX];
		memcpy(tmp,a,intsz*n);
		int N = getN(n-1)*2;
		if(de)assert(a[0]==1);
		memcpy(b,a,intsz*N);
		Inv(a,b,n);
		Dev(b,n);
		
		initR(N,CTZ(N));
		NTT(a,N,1);
		NTT(b,N,1);
		ll Ni = pw(N,mod-2);
		rep(i,0,N)b[i] = ((ll)a[i]*b[i]%mod*Ni)%mod;
		NTT(b,N,-1);
		memset(b+n,0,intsz*(N-n));
		Inter(b,n);
		memcpy(a,tmp,intsz*n);
		memset(a+n,0,intsz*(N-n));
		return ;
	}
	
	void Exp(int *b,int *a,int n){
	//Exp(out,in,n) , won't destroy a
	// mod x^n
		static int c[MAX],d[MAX];
		if(de)assert(a[0]==0);
		int N = 1,lim = 0;
		b[0] = 1,b[1] = 0;
		while(N<n){
			N <<= 1;
			lim++;
			memset(b+N,0,intsz*N);
			Ln(c,b,N);
			memcpy(d,a,intsz*N);
			memset(d+N,0,intsz*N);
			initR(N*2,lim+1);
			NTT(b,N*2,1);
			NTT(c,N*2,1);
			NTT(d,N*2,1);
			ll Ni = pw(N*2,mod-2);
			rep(i,0,N*2)b[i] = (1ll-c[i]+d[i]+mod)%mod*b[i]%mod*Ni%mod;
			NTT(b,N*2,-1);
			memset(b+N,0,intsz*N);
		}
		memset(b+n,0,intsz*(N-n));
		return ;
	}
}
int U0[MAX],R0[MAX];
int A[MAX],B[MAX],C[MAX],D[MAX],E[MAX],Ctmp[MAX];
int a[MAX],b[MAX],c[MAX],d[MAX],e[MAX],f[MAX];
int F[MAX],Q[MAX],M[MAX],iM[MAX],tmp1[MAX],tmp2[MAX];
signed main(){
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	int n = rd();
	int N = 2;
	R0[1] = 1;
	// U0[2] = 1;
	// R0[2] = 1;
	// U0[3] = 499122179;
	// R0[3] = 499122178;
//	499122179 499122178
	while(N<=n){
		// n
		N <<= 1;
		memset(A,0,intsz*N);
		memset(B,0,intsz*N);
		poly::Exp(A+1,R0,N-1);
		poly::Exp(B,U0,N);

		memcpy(Ctmp,U0,intsz*N/2);
		poly::Mul(Ctmp,N/2-1,R0,N/2-1);
		poly::Exp(C+1,Ctmp,N-1);
		
		memcpy(E,U0,intsz*N/2);
		memcpy(D,U0,intsz*N/2);
		poly::Mul(E,N/2-1,D,N/2-1);
		poly::Mul(D,N/2-1,E,N-1);
		memset(D+N,0,intsz*N/2);

		memcpy(a,U0,intsz*N/2);
		a[0] = (a[0]+1)%mod;
		poly::Mul(a,N/2-1,R0,N/2-1);
		a[0] = (a[0]+1)%mod;
		poly::Mul(a,N-1,C,N-1);
		memset(a+N,0,intsz*N);
		a[0] = (a[0]+1)%mod;
		
		rep(i,0,N)b[i] = (U0[i]+E[i])%mod;
		poly::Mul(b,N-1,C,N-1);
		memset(b+N,0,intsz*N);
		b[0] = (b[0]-1+mod)%mod;

		memcpy(c,C,intsz*N);
		poly::Mul(c,N-1,U0,N-1);
		memset(c+N,0,intsz*N);
		rep(i,0,N)c[i] = ((ll)R0[i]-U0[i]-C[i]-c[i]+mod*4ll)%mod;

		rep(i,0,N)d[i] = (A[i]+E[i]*3ll)%mod;
		memcpy(e,U0,intsz*N/2);
		e[0] = (e[0]+1)%mod;
		poly::Mul(e,N/2-1,A,N-1);
		memset(e+N,0,intsz*N/2);
		e[0] = (e[0]-1+mod)%mod;
		rep(i,0,N)f[i] = ((ll)R0[i]-D[i]-e[i]+mod+mod)%mod;
		f[0] = (f[0]-1+mod)%mod;

		memcpy(tmp1,a,intsz*N);
		poly::Mul(tmp1,N-1,e,N-1);
		memset(tmp1+N,0,intsz*N);
		memcpy(tmp2,b,intsz*N);
		poly::Mul(tmp2,N-1,d,N-1);
		memset(tmp2+N,0,intsz*N);
		rep(i,0,N)M[i] = (tmp1[i]-tmp2[i]+mod)%mod;

		memcpy(tmp1,c,intsz*N);
		poly::Mul(tmp1,N-1,e,N-1);
		memset(tmp1+N,0,intsz*N);
		memcpy(tmp2,b,intsz*N);
		poly::Mul(tmp2,N-1,f,N-1);
		memset(tmp2+N,0,intsz*N);
		rep(i,0,N)F[i] = (tmp1[i]-tmp2[i]+mod)%mod;

		memcpy(tmp1,a,intsz*N);
		poly::Mul(tmp1,N-1,f,N-1);
		memset(tmp1+N,0,intsz*N);
		memcpy(tmp2,c,intsz*N);
		poly::Mul(tmp2,N-1,d,N-1);
		memset(tmp2+N,0,intsz*N);
		rep(i,0,N)Q[i] = (tmp1[i]-tmp2[i]+mod)%mod;

		poly::Inv(iM,M,N);
		poly::Mul(F,N-1,iM,N-1);
		memset(F+N,0,intsz*N);
		rep(i,N/2,N)U0[i] = F[i];

		poly::Mul(Q,N-1,iM,N-1);
		memset(Q+N,0,intsz*N);
		rep(i,N/2,N)R0[i] = Q[i];
	}
	ll ans = (U0[n]+R0[n])%mod;
	repp(i,2,n)ans = (ans*i)%mod;
	cout<<ans<<endl;
	return 0;
}
/**
0 0
1 0
1 1
499122179 499122178
166374065 665496239
623902737 457528672
108143186 981606976
525464880 500508714
*/

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5668kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #3:

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

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #4:

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

input:

100

output:

413875584

result:

ok 1 number(s): "413875584"

Test #5:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

2

output:

4

result:

ok 1 number(s): "4"

Test #7:

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

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #8:

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

input:

4

output:

236

result:

ok 1 number(s): "236"

Test #9:

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

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #10:

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

input:

6

output:

55182

result:

ok 1 number(s): "55182"

Test #11:

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

input:

7

output:

1165220

result:

ok 1 number(s): "1165220"

Test #12:

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

input:

8

output:

29013896

result:

ok 1 number(s): "29013896"

Test #13:

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

input:

9

output:

832517514

result:

ok 1 number(s): "832517514"

Test #14:

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

input:

10

output:

96547079

result:

ok 1 number(s): "96547079"

Test #15:

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

input:

11

output:

296100513

result:

ok 1 number(s): "296100513"

Test #16:

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

input:

12

output:

672446962

result:

ok 1 number(s): "672446962"

Test #17:

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

input:

13

output:

986909297

result:

ok 1 number(s): "986909297"

Test #18:

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

input:

14

output:

306542229

result:

ok 1 number(s): "306542229"

Test #19:

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

input:

15

output:

8548107

result:

ok 1 number(s): "8548107"

Test #20:

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

input:

16

output:

773960239

result:

ok 1 number(s): "773960239"

Test #21:

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

input:

17

output:

611627547

result:

ok 1 number(s): "611627547"

Test #22:

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

input:

18

output:

91793980

result:

ok 1 number(s): "91793980"

Test #23:

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

input:

19

output:

689202618

result:

ok 1 number(s): "689202618"

Test #24:

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

input:

20

output:

605957782

result:

ok 1 number(s): "605957782"

Test #25:

score: 0
Accepted
time: 249ms
memory: 51164kb

input:

10000

output:

713782215

result:

ok 1 number(s): "713782215"

Test #26:

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

input:

20000

output:

337916836

result:

ok 1 number(s): "337916836"

Test #27:

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

input:

30000

output:

580803285

result:

ok 1 number(s): "580803285"

Test #28:

score: 0
Accepted
time: 1175ms
memory: 52524kb

input:

40000

output:

732660392

result:

ok 1 number(s): "732660392"

Test #29:

score: 0
Accepted
time: 1166ms
memory: 52576kb

input:

50000

output:

660835595

result:

ok 1 number(s): "660835595"

Test #30:

score: 0
Accepted
time: 1171ms
memory: 52520kb

input:

60000

output:

323452070

result:

ok 1 number(s): "323452070"

Test #31:

score: 0
Accepted
time: 2529ms
memory: 55348kb

input:

70000

output:

307315915

result:

ok 1 number(s): "307315915"

Test #32:

score: 0
Accepted
time: 2526ms
memory: 55404kb

input:

80000

output:

951757567

result:

ok 1 number(s): "951757567"

Test #33:

score: 0
Accepted
time: 2521ms
memory: 54372kb

input:

90000

output:

426123208

result:

ok 1 number(s): "426123208"

Test #34:

score: 0
Accepted
time: 2519ms
memory: 54292kb

input:

100000

output:

827418228

result:

ok 1 number(s): "827418228"

Test #35:

score: 0
Accepted
time: 2526ms
memory: 54444kb

input:

110000

output:

541614559

result:

ok 1 number(s): "541614559"

Test #36:

score: 0
Accepted
time: 2529ms
memory: 55460kb

input:

120000

output:

184688986

result:

ok 1 number(s): "184688986"

Test #37:

score: 0
Accepted
time: 2524ms
memory: 54060kb

input:

130000

output:

898089371

result:

ok 1 number(s): "898089371"

Test #38:

score: 0
Accepted
time: 5493ms
memory: 57392kb

input:

140000

output:

949540221

result:

ok 1 number(s): "949540221"

Test #39:

score: 0
Accepted
time: 5485ms
memory: 56504kb

input:

150000

output:

767689851

result:

ok 1 number(s): "767689851"

Test #40:

score: 0
Accepted
time: 5495ms
memory: 58024kb

input:

160000

output:

553494563

result:

ok 1 number(s): "553494563"

Test #41:

score: 0
Accepted
time: 5480ms
memory: 57880kb

input:

170000

output:

270711750

result:

ok 1 number(s): "270711750"

Test #42:

score: 0
Accepted
time: 5492ms
memory: 57960kb

input:

180000

output:

108155689

result:

ok 1 number(s): "108155689"

Test #43:

score: 0
Accepted
time: 5476ms
memory: 56396kb

input:

190000

output:

327542856

result:

ok 1 number(s): "327542856"

Test #44:

score: 0
Accepted
time: 5491ms
memory: 57732kb

input:

200000

output:

236144151

result:

ok 1 number(s): "236144151"

Test #45:

score: 0
Accepted
time: 5498ms
memory: 57904kb

input:

198798

output:

16935264

result:

ok 1 number(s): "16935264"

Extra Test:

score: 0
Extra Test Passed