QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307255#8010. Hierarchies of JudgesKevin5307TL 5946ms108072kbC++236.1kb2024-01-18 11:29:022024-01-18 11:29:03

Judging History

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

  • [2024-01-18 11:29:03]
  • 评测
  • 测评结果:TL
  • 用时:5946ms
  • 内存:108072kb
  • [2024-01-18 11:29:02]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
namespace Polynomial
{
	#undef ll
	#undef sz
	#undef rev
	using ll=long long;
	using poly=vector<ll>;
	const ll mod=998244353;
	ll ksm(ll a,ll b)
	{
		ll ans=1;
		while(b)
		{
			if(b&1) ans=ans*a%mod;
			b>>=1;
			a=a*a%mod;
		}
		return ans;
	}
	inline int sz(const poly &p)
	{
		return p.size();
	}
	namespace builtin
	{
		poly NTT(poly p,int m)
		{
			assert(__builtin_popcount(m)==1);
			const ll g=3;
			p.resize(m);
			vector<int> rev(m);
			for(int i=0;i<m;i++)
				rev[i]=(rev[i>>1]>>1)|((i&1)*(m>>1));
			for(int i=0;i<m;i++)
				if(rev[i]<i)
					swap(p[i],p[rev[i]]);
			for(int i=1;i<m;i<<=1)
			{
				ll gn=ksm(g,(mod-1)/i/2);
				for(int j=0;j<m;j+=(i<<1))
				{
					ll g0=1;
					for(int k=0;k<i;k++,g0=g0*gn%mod)
					{
						ll x=p[j+k],y=g0*p[i+j+k]%mod;
						p[j+k]=(x+y)%mod;
						p[i+j+k]=(x+mod-y)%mod;
					}
				}
			}
			return p;
		}
		poly INTT(poly p,int m)
		{
			assert(__builtin_popcount(m)==1);
			const ll g=3;
			p.resize(m);
			vector<int> rev(m);
			for(int i=0;i<m;i++)
				rev[i]=(rev[i>>1]>>1)|((i&1)*(m>>1));
			for(int i=0;i<m;i++)
				if(rev[i]<i)
					swap(p[i],p[rev[i]]);
			for(int i=1;i<m;i<<=1)
			{
				ll gn=ksm(g,(mod-1)/i/2*(mod-2));
				for(int j=0;j<m;j+=(i<<1))
				{
					ll g0=1;
					for(int k=0;k<i;k++,g0=g0*gn%mod)
					{
						ll x=p[j+k],y=g0*p[i+j+k]%mod;
						p[j+k]=(x+y)%mod;
						p[i+j+k]=(x+mod-y)%mod;
					}
				}
			}
			ll val=ksm(m,mod-2);
			for(int i=0;i<m;i++)
				p[i]=p[i]*val%mod;
			return p;
		}
	}
	const poly operator +(const poly &a,const poly &b)
	{
		int p=sz(a),q=sz(b);
		int n=max(p,q);
		poly ret(n,0);
		for(int i=0;i<n;i++)
		{
			if(i<p) ret[i]+=a[i];
			if(i<q) ret[i]+=b[i];
			if(ret[i]>=mod) ret[i]-=mod;
		}
		return ret;
	}
	const poly operator -(const poly &a,const poly &b)
	{
		int p=sz(a),q=sz(b);
		int n=max(p,q);
		poly ret(n,0);
		for(int i=0;i<n;i++)
		{
			if(i<p) ret[i]+=a[i];
			if(i<q) ret[i]+=mod-b[i];
			if(ret[i]>=mod) ret[i]-=mod;
		}
		return ret;
	}
	poly operator %(poly p,int n)
	{
		p.resize(n);
		return p;
	}
	poly operator *(poly a,poly b)
	{
		const ll g=3;
		int len=sz(a)+sz(b);
		int m=1;
		while(m<sz(a)+sz(b)) m*=2;
		a.resize(m);
		b.resize(m);
		vector<int> rev(m);
		for(int i=0;i<m;i++)
			rev[i]=(rev[i>>1]>>1)|((i&1)*(m>>1));
		for(int i=0;i<m;i++)
			if(rev[i]<i)
			{
				swap(a[i],a[rev[i]]);
				swap(b[i],b[rev[i]]);
			}
		for(int i=1;i<m;i<<=1)
		{
			ll gn=ksm(g,(mod-1)/i/2);
			for(int j=0;j<m;j+=(i<<1))
			{
				ll g0=1;
				for(int k=0;k<i;k++,g0=g0*gn%mod)
				{
					{
						ll x=a[j+k],y=g0*a[i+j+k]%mod;
						a[j+k]=(x+y)%mod;
						a[i+j+k]=(x+mod-y)%mod;
					}
					{
						ll x=b[j+k],y=g0*b[i+j+k]%mod;
						b[j+k]=(x+y)%mod;
						b[i+j+k]=(x+mod-y)%mod;
					}
				}
			}
		}
		for(int i=0;i<m;i++)
			a[i]=a[i]*b[i]%mod;
		for(int i=0;i<m;i++)
			if(rev[i]<i)
				swap(a[i],a[rev[i]]);
		for(int i=1;i<m;i<<=1)
		{
			ll gn=ksm(g,(mod-1)/i/2*(mod-2));
			for(int j=0;j<m;j+=(i<<1))
			{
				ll g0=1;
				for(int k=0;k<i;k++,g0=g0*gn%mod)
				{
					ll x=a[j+k],y=g0*a[i+j+k]%mod;
					a[j+k]=(x+y)%mod;
					a[i+j+k]=(x+mod-y)%mod;
				}
			}
		}
		ll val=ksm(m,mod-2);
		for(int i=0;i<m;i++)
			a[i]=a[i]*val%mod;
		a.resize(len-1);
		return a;
	}
	poly inv(poly p,int deg)
	{
		p.resize(deg);
		if(deg==1) return {ksm(p[0],mod-2)};
		poly w=inv(p,(deg+1)/2);
		poly g=w+w-p*w*w;
		g.resize(deg);
		return g;
	}
	poly deriv(poly p)
	{
		for(int i=0;i<sz(p);i++)
			p[i]=p[i]*i%mod;
		p.erase(p.begin());
		return p;
	}
	poly integ(poly p)
	{
		p.insert(p.begin(),0);
		for(int i=0;i<sz(p);i++)
			p[i]=p[i]*ksm(i,mod-2)%mod;
		return p;
	}
	poly ln(poly p,int deg)
	{
		p=integ(deriv(p)*inv(p,deg));
		p.resize(deg);
		return p;
	}
	poly exp(poly p,int deg)
	{
		p.resize(deg);
		if(deg==1)
			return {1};
		poly g=exp(p,(deg+1)/2);
		g=g*(poly{1}-ln(g,deg)+p);
		g.resize(deg);
		return g;
	}
}
using namespace Polynomial;
pair<poly,poly> solve(int n)
{
	if(n==1) return mp(poly{0},poly{0});
	pair<poly,poly> pr=solve((n+1)/2);
	poly F0=pr.first,G0=pr.second;
	poly eFG=exp(F0*G0,n);
	poly eF=exp(F0,n);
	int m=1;
	while(m<=n+n+n/2+2) m<<=1;
	F0=builtin::NTT(F0,m);
	G0=builtin::NTT(G0,m);
	eFG=builtin::NTT(eFG,m);
	eF=builtin::NTT(eF,m);
	poly x=builtin::NTT({0,1},m);
	poly F1(m),G1(m),C1(m),F2(m),G2(m),C2(m);
	for(int i=0;i<m;i++)
	{
		F1[i]=(1-x[i]*(1+G0[i])%mod*G0[i]%mod*eFG[i]%mod+mod)%mod;
		G1[i]=(mod-1-x[i]*(1+F0[i]+F0[i]*G0[i]%mod)%mod*eFG[i]%mod+mod)%mod;
		C1[i]=(G0[i]-F0[i]+x[i]*(1+G0[i])%mod*eFG[i]%mod+F0[i]*F1[i]+G0[i]*G1[i]+mod)%mod;
		F2[i]=(1-x[i]*(1+G0[i])%mod*eF[i]%mod+mod)%mod;
		G2[i]=((mod-3)*G0[i]%mod*G0[i]%mod-x[i]*eF[i]%mod+mod)%mod;
		C2[i]=(G0[i]*G0[i]%mod*G0[i]%mod-F0[i]+x[i]*(1+G0[i])%mod*eF[i]%mod+F0[i]*F2[i]+G0[i]*G2[i]+mod)%mod;
	}
	F1=builtin::INTT(F1,m)%n;
	G1=builtin::INTT(G1,m)%n;
	C1=builtin::INTT(C1,m)%n;
	F2=builtin::INTT(F2,m)%n;
	G2=builtin::INTT(G2,m)%n;
	C2=builtin::INTT(C2,m)%n;
	poly C11=C1*F2%n;
	poly G11=G1*F2%n;
	poly C21=C2*F1%n;
	poly G21=G2*F1%n;
	poly G=(C11-C21)*inv(G11-G21,n);
	G.resize(n);
	poly F=(C1-G1*G)*inv(F1,n);
	F.resize(n);
	return mp(F,G);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	pair<poly,poly> pr=solve(n+1);
	ll ans=(pr.first.back()+pr.second.back())%mod;
	for(int i=1;i<=n;i++)
		ans=ans*i%mod;
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #3:

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

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #4:

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

input:

100

output:

413875584

result:

ok 1 number(s): "413875584"

Test #5:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

2

output:

4

result:

ok 1 number(s): "4"

Test #7:

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

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #8:

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

input:

4

output:

236

result:

ok 1 number(s): "236"

Test #9:

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

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #10:

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

input:

6

output:

55182

result:

ok 1 number(s): "55182"

Test #11:

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

input:

7

output:

1165220

result:

ok 1 number(s): "1165220"

Test #12:

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

input:

8

output:

29013896

result:

ok 1 number(s): "29013896"

Test #13:

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

input:

9

output:

832517514

result:

ok 1 number(s): "832517514"

Test #14:

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

input:

10

output:

96547079

result:

ok 1 number(s): "96547079"

Test #15:

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

input:

11

output:

296100513

result:

ok 1 number(s): "296100513"

Test #16:

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

input:

12

output:

672446962

result:

ok 1 number(s): "672446962"

Test #17:

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

input:

13

output:

986909297

result:

ok 1 number(s): "986909297"

Test #18:

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

input:

14

output:

306542229

result:

ok 1 number(s): "306542229"

Test #19:

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

input:

15

output:

8548107

result:

ok 1 number(s): "8548107"

Test #20:

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

input:

16

output:

773960239

result:

ok 1 number(s): "773960239"

Test #21:

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

input:

17

output:

611627547

result:

ok 1 number(s): "611627547"

Test #22:

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

input:

18

output:

91793980

result:

ok 1 number(s): "91793980"

Test #23:

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

input:

19

output:

689202618

result:

ok 1 number(s): "689202618"

Test #24:

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

input:

20

output:

605957782

result:

ok 1 number(s): "605957782"

Test #25:

score: 0
Accepted
time: 218ms
memory: 8980kb

input:

10000

output:

713782215

result:

ok 1 number(s): "713782215"

Test #26:

score: 0
Accepted
time: 455ms
memory: 14788kb

input:

20000

output:

337916836

result:

ok 1 number(s): "337916836"

Test #27:

score: 0
Accepted
time: 688ms
memory: 22524kb

input:

30000

output:

580803285

result:

ok 1 number(s): "580803285"

Test #28:

score: 0
Accepted
time: 989ms
memory: 26376kb

input:

40000

output:

732660392

result:

ok 1 number(s): "732660392"

Test #29:

score: 0
Accepted
time: 1313ms
memory: 30336kb

input:

50000

output:

660835595

result:

ok 1 number(s): "660835595"

Test #30:

score: 0
Accepted
time: 1475ms
memory: 40604kb

input:

60000

output:

323452070

result:

ok 1 number(s): "323452070"

Test #31:

score: 0
Accepted
time: 2024ms
memory: 46964kb

input:

70000

output:

307315915

result:

ok 1 number(s): "307315915"

Test #32:

score: 0
Accepted
time: 2078ms
memory: 49348kb

input:

80000

output:

951757567

result:

ok 1 number(s): "951757567"

Test #33:

score: 0
Accepted
time: 2772ms
memory: 56204kb

input:

90000

output:

426123208

result:

ok 1 number(s): "426123208"

Test #34:

score: 0
Accepted
time: 2799ms
memory: 56508kb

input:

100000

output:

827418228

result:

ok 1 number(s): "827418228"

Test #35:

score: 0
Accepted
time: 3134ms
memory: 78816kb

input:

110000

output:

541614559

result:

ok 1 number(s): "541614559"

Test #36:

score: 0
Accepted
time: 3175ms
memory: 80844kb

input:

120000

output:

184688986

result:

ok 1 number(s): "184688986"

Test #37:

score: 0
Accepted
time: 3168ms
memory: 81584kb

input:

130000

output:

898089371

result:

ok 1 number(s): "898089371"

Test #38:

score: 0
Accepted
time: 4446ms
memory: 94792kb

input:

140000

output:

949540221

result:

ok 1 number(s): "949540221"

Test #39:

score: 0
Accepted
time: 4445ms
memory: 94960kb

input:

150000

output:

767689851

result:

ok 1 number(s): "767689851"

Test #40:

score: 0
Accepted
time: 4500ms
memory: 96668kb

input:

160000

output:

553494563

result:

ok 1 number(s): "553494563"

Test #41:

score: 0
Accepted
time: 4513ms
memory: 96504kb

input:

170000

output:

270711750

result:

ok 1 number(s): "270711750"

Test #42:

score: 0
Accepted
time: 5946ms
memory: 108072kb

input:

180000

output:

108155689

result:

ok 1 number(s): "108155689"

Test #43:

score: 0
Accepted
time: 5922ms
memory: 107356kb

input:

190000

output:

327542856

result:

ok 1 number(s): "327542856"

Test #44:

score: -100
Time Limit Exceeded

input:

200000

output:

236144151

result: