QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307228 | #8010. Hierarchies of Judges | Kevin5307 | TL | 5120ms | 52484kb | C++23 | 4.4kb | 2024-01-18 10:55:28 | 2024-01-18 10:55:29 |
Judging History
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();
}
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 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 F1=poly{1}-poly{0,1}*(poly{1}+G0)*G0*exp(F0*G0,n);
poly G1=poly{mod-1}-poly{0,1}*(poly{1}+F0+F0*G0)*exp(F0*G0,n);
poly C1=G0-F0+poly{0,1}*(poly{1}+G0)*exp(F0*G0,n)+F0*F1+G0*G1;
poly F2=poly{1}-poly{0,1}*(poly{1}+G0)*exp(F0,n);
poly G2=poly{mod-3}*G0*G0-poly{0,1}*exp(F0,n);
poly C2=G0*G0*G0-F0+poly{0,1}*(poly{1}+G0)*exp(F0,n)+F0*F2+G0*G2;
poly C11=C1*F2;
poly G11=G1*F2;
poly C21=C2*F1;
poly G21=G2*F1;
poly G=(C11-C21)*inv(G11-G21,n);
G.resize(n);
poly F=(C1-G1*G)*inv(F1,n);
F.resize(n);
poly val1=F*F1+G*G1-C1;
poly val2=F*F2+G*G2-C2;
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #4:
score: 0
Accepted
time: 6ms
memory: 3972kb
input:
100
output:
413875584
result:
ok 1 number(s): "413875584"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
2
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
4
output:
236
result:
ok 1 number(s): "236"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
6
output:
55182
result:
ok 1 number(s): "55182"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
7
output:
1165220
result:
ok 1 number(s): "1165220"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
8
output:
29013896
result:
ok 1 number(s): "29013896"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
9
output:
832517514
result:
ok 1 number(s): "832517514"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
10
output:
96547079
result:
ok 1 number(s): "96547079"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
11
output:
296100513
result:
ok 1 number(s): "296100513"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
12
output:
672446962
result:
ok 1 number(s): "672446962"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
13
output:
986909297
result:
ok 1 number(s): "986909297"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
14
output:
306542229
result:
ok 1 number(s): "306542229"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
15
output:
8548107
result:
ok 1 number(s): "8548107"
Test #20:
score: 0
Accepted
time: 2ms
memory: 3812kb
input:
16
output:
773960239
result:
ok 1 number(s): "773960239"
Test #21:
score: 0
Accepted
time: 2ms
memory: 3888kb
input:
17
output:
611627547
result:
ok 1 number(s): "611627547"
Test #22:
score: 0
Accepted
time: 2ms
memory: 3600kb
input:
18
output:
91793980
result:
ok 1 number(s): "91793980"
Test #23:
score: 0
Accepted
time: 2ms
memory: 3664kb
input:
19
output:
689202618
result:
ok 1 number(s): "689202618"
Test #24:
score: 0
Accepted
time: 2ms
memory: 3680kb
input:
20
output:
605957782
result:
ok 1 number(s): "605957782"
Test #25:
score: 0
Accepted
time: 529ms
memory: 9812kb
input:
10000
output:
713782215
result:
ok 1 number(s): "713782215"
Test #26:
score: 0
Accepted
time: 1123ms
memory: 15908kb
input:
20000
output:
337916836
result:
ok 1 number(s): "337916836"
Test #27:
score: 0
Accepted
time: 1688ms
memory: 22200kb
input:
30000
output:
580803285
result:
ok 1 number(s): "580803285"
Test #28:
score: 0
Accepted
time: 2395ms
memory: 28060kb
input:
40000
output:
732660392
result:
ok 1 number(s): "732660392"
Test #29:
score: 0
Accepted
time: 3394ms
memory: 34012kb
input:
50000
output:
660835595
result:
ok 1 number(s): "660835595"
Test #30:
score: 0
Accepted
time: 3603ms
memory: 39724kb
input:
60000
output:
323452070
result:
ok 1 number(s): "323452070"
Test #31:
score: 0
Accepted
time: 4998ms
memory: 48116kb
input:
70000
output:
307315915
result:
ok 1 number(s): "307315915"
Test #32:
score: 0
Accepted
time: 5120ms
memory: 52484kb
input:
80000
output:
951757567
result:
ok 1 number(s): "951757567"
Test #33:
score: -100
Time Limit Exceeded
input:
90000