QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307252 | #8010. Hierarchies of Judges | Kevin5307 | WA | 3ms | 3908kb | C++23 | 6.1kb | 2024-01-18 11:27:02 | 2024-01-18 11:27:03 |
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();
}
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+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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #4:
score: 0
Accepted
time: 3ms
memory: 3908kb
input:
100
output:
413875584
result:
ok 1 number(s): "413875584"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
2
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
4
output:
236
result:
ok 1 number(s): "236"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3752kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
6
output:
55182
result:
ok 1 number(s): "55182"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
7
output:
1165220
result:
ok 1 number(s): "1165220"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
8
output:
29013896
result:
ok 1 number(s): "29013896"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
9
output:
832517514
result:
ok 1 number(s): "832517514"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
10
output:
96547079
result:
ok 1 number(s): "96547079"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
11
output:
296100513
result:
ok 1 number(s): "296100513"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
12
output:
672446962
result:
ok 1 number(s): "672446962"
Test #17:
score: -100
Wrong Answer
time: 1ms
memory: 3564kb
input:
13
output:
553513370
result:
wrong answer 1st numbers differ - expected: '986909297', found: '553513370'