QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#343480 | #8010. Hierarchies of Judges | ucup-team1525# | AC ✓ | 2524ms | 28096kb | C++17 | 8.7kb | 2024-03-02 17:20:19 | 2024-03-02 17:20:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
const int N=1<<19;
const int mod=998244353;
using arr=int[N+5];
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int sub(int x,int y){ return (x-=y)<0?x+mod:x; }
int red(int &x){ return x+=(x>>31)&mod; }
int ksm(ll x,int tp,int s=1){
for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
return s;
}
arr fac,ifac,inv;
void prep(){
fac[0]=ifac[0]=1;
for(int i=1;i<=N;i++) fac[i]=1ll*fac[i-1]*i%mod;
ifac[N]=ksm(fac[N],mod-2);
for(int i=N;i;i--) ifac[i-1]=1ll*ifac[i]*i%mod;
for(int i=1;i<=N;i++) inv[i]=1ll*ifac[i]*fac[i-1]%mod;
}
namespace poly{
int L,iv;
arr w,rev;
arr pa,pb;
#define szf sizeof(int)
void cl(arr a){ memset(a,0,L*szf); }
void r_prep(){
int L=N>>1;
int val=ksm(3,(mod-1)/N);
w[L]=1;
for(int i=1;i<L;i++) w[i+L]=1ll*w[i+L-1]*val%mod;
for(int i=L-1;i;i--) w[i]=w[i<<1];
}
void pre_n(int n){
L=1; while(L<n) L<<=1;
iv=mod-(mod-1)/L;
for(int i=1;i<L;i++) rev[i]=(rev[i>>1]>>1)|(i&1?L>>1:0);
}
void FFT(arr t,bool ok=1){
int x,y;
for(int i=1;i<L;i++)
if(i<rev[i]) swap(t[i],t[rev[i]]);
for(int i=1;i<L;i<<=1)
for(int j=0;j<L;j+=i<<1)
for(int l=0;l<i;l++){
x=t[j+l],y=1ll*t[i+j+l]*w[i+l]%mod;
t[i+j+l]=sub(x,y),t[j+l]=add(x,y);
}
if(!ok){
reverse(t+1,t+L);
for(int i=0;i<L;i++) t[i]=1ll*t[i]*iv%mod;
}
}
void NTT(arr a){ FFT(a); }
void INTT(arr a){ FFT(a,0); }
void NTT(arr a,arr b){ memcpy(b,a,L*szf); FFT(b); }
void INTT(arr a,arr b){ memcpy(b,a,L*szf); FFT(b,0); }
void Mult(arr a,arr b,arr c,int n){
pre_n(n);
NTT(a,pa); NTT(b,pb);
for(int i=0;i<L;i++) c[i]=1ll*pa[i]*pb[i]%mod;
INTT(c);
fill(c+n,c+L,0);
cl(pa); cl(pb);
}
}
int n;
arr f0,f1,f1f0,f02;
arr ef1,ef1f0,ivf0,ef02;
void solve(int l,int r){
// fprintf(stderr,"%d %d\n",l,r);
if(l+1==r){
if(l>0){
ef1[l]=add(1ll*ef1[l]*inv[l]%mod,f1[l]);
ef1f0[l]=add(1ll*ef1f0[l]*inv[l]%mod,f1f0[l]);
ef02[l]=add(ef02[l],f02[l]);
ivf0[l]=add(ivf0[l],f0[l]);
}
// printf("%d: %d %d %d %d %d %d %d\n",l,f0[l],f1[l],f02[l],ivf0[l],ef1[l],ef1f0[l],ef02[l]);
return;
}
int mid=l+r>>1;
solve(l,mid);
// fprintf(stderr,"%d %d\n",l,r);
if(!l){
int L1=mid-l,L=r-l;
static arr ta,tb,tc;
memcpy(ta,f0,L1*sizeof(int));
memcpy(tb,f1,L1*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
f1f0[j]=add(f1f0[j],tc[j]);
poly::Mult(ta,ta,tc,L);
for(int j=mid;j<r;j++)
f02[j]=add(f02[j],tc[j]);
memcpy(tb,ivf0,L1*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ivf0[j]=add(ivf0[j],tc[j]);
for(int j=0;j<L1;j++)
ta[j]=sub(ef1[j],ef1f0[j]);
poly::Mult(ta,tb,tc,L);
for(int j=mid-1;j+1<r;j++)
f0[j+1]=add(f0[j+1],tc[j]);
for(int j=0;j<L1;j++)
ta[j]=sub(ef1[j],ef02[j]);
poly::Mult(ta,tb,tc,L);
for(int j=mid-1;j+1<r;j++)
f1[j+1]=add(f1[j+1],tc[j]);
memcpy(ta,f02,L1*sizeof(int));
memcpy(tb,ef1f0,L1*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef02[j]=add(ef02[j],tc[j]);
for(int j=0;j<L1;j++)
ta[j]=1ll*j*f1f0[j]%mod;
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef1f0[j]=add(ef1f0[j],tc[j]);
for(int j=0;j<L1;j++)
ta[j]=1ll*j*f1[j]%mod;
memcpy(tb,ef1,L1*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef1[j]=add(ef1[j],tc[j]);
// printf("%d\n",ef1[1]);
memset(ta,0,L*sizeof(int));
memset(tb,0,L*sizeof(int));
memset(tc,0,L*sizeof(int));
}
else{
// printf("%d\n",f1[3]);
int L1=mid-l,L=r-l;
static arr ta,tb,tc;
memcpy(ta,f0+l,L1*sizeof(int));
memcpy(tb,f1,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
f1f0[j]=add(f1f0[j],tc[j-l]);
memcpy(ta,f1+l,L1*sizeof(int));
memcpy(tb,f0,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
f1f0[j]=add(f1f0[j],tc[j-l]);
memcpy(ta,f0+l,L1*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
f02[j]=add(f02[j],add(tc[j-l],tc[j-l]));
memcpy(tb,ivf0,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ivf0[j]=add(ivf0[j],tc[j-l]);
memcpy(ta,ivf0+l,L1*sizeof(int));
memcpy(tb,f0,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ivf0[j]=add(ivf0[j],tc[j-l]);
for(int j=0;j<L;j++)
tb[j]=sub(ef1[j],ef1f0[j]);
poly::Mult(ta,tb,tc,L);
for(int j=mid-1;j+1<r;j++)
f0[j+1]=add(f0[j+1],tc[j-l]);
for(int j=0;j<L;j++)
tb[j]=sub(ef1[j],ef02[j]);
poly::Mult(ta,tb,tc,L);
for(int j=mid-1;j+1<r;j++)
f1[j+1]=add(f1[j+1],tc[j-l]);
for(int j=l;j<mid;j++)
ta[j-l]=sub(ef1[j],ef1f0[j]);
memcpy(tb,ivf0,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid-1;j+1<r;j++)
f0[j+1]=add(f0[j+1],tc[j-l]);
for(int j=l;j<mid;j++)
ta[j-l]=sub(ef1[j],ef02[j]);
poly::Mult(ta,tb,tc,L);
for(int j=mid-1;j+1<r;j++)
f1[j+1]=add(f1[j+1],tc[j-l]);
memcpy(ta,ef1f0+l,L1*sizeof(int));
memcpy(tb,f02,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef02[j]=add(ef02[j],tc[j-l]);
memcpy(ta,f02+l,L1*sizeof(int));
memcpy(tb,ef1f0,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef02[j]=add(ef02[j],tc[j-l]);
for(int j=l;j<mid;j++)
ta[j-l]=1ll*j*f1[j]%mod;
memcpy(tb,ef1,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef1[j]=add(ef1[j],tc[j-l]);
memcpy(ta,ef1+l,L1*sizeof(int));
for(int j=0;j<L;j++)
tb[j]=1ll*j*f1[j]%mod;
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef1[j]=add(ef1[j],tc[j-l]);
for(int j=l;j<mid;j++)
ta[j-l]=1ll*j*f1f0[j]%mod;
memcpy(tb,ef1f0,L*sizeof(int));
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef1f0[j]=add(ef1f0[j],tc[j-l]);
memcpy(ta,ef1f0+l,L1*sizeof(int));
for(int j=0;j<L;j++)
tb[j]=1ll*j*f1f0[j]%mod;
poly::Mult(ta,tb,tc,L);
for(int j=mid;j<r;j++)
ef1f0[j]=add(ef1f0[j],tc[j-l]);
memset(ta,0,L*sizeof(int));
memset(tb,0,L*sizeof(int));
memset(tc,0,L*sizeof(int));
}
solve(mid,r);
}
int main(){
scanf("%d",&n);
prep();
poly::r_prep();
int L=0;
while(n>>L) L++;
ef1[0]=ef1f0[0]=ivf0[0]=1;
solve(0,1<<L);
// printf("ans1: %lld\n",1ll*add(f1[n],f0[n])*fac[n]%mod);
// f1[1]=1;
// // memset(f0,0,sizeof f0);
// for(int i=1;i<=n;i++){
// for(int j=1;j<=i;j++)
// f1f0[i]=(f1f0[i]+1ll*f1[j]*f0[i-j])%mod;
// for(int j=1;j<=i;j++)
// f02[i]=(f02[i]+1ll*f0[j]*f0[i-j])%mod;
// for(int j=1;j<=i;j++)
// ivf0[i]=(ivf0[i]+1ll*f0[j]*ivf0[i-j])%mod;
// for(int j=1;j<=i;j++)
// ef1[i]=(ef1[i]+1ll*j*f1[j]%mod*ef1[i-j])%mod;
// ef1[i]=1ll*ef1[i]*inv[i]%mod;
// for(int j=1;j<=i;j++)
// ef1f0[i]=(ef1f0[i]+1ll*j*f1f0[j]%mod*ef1f0[i-j])%mod;
// ef1f0[i]=1ll*ef1f0[i]*inv[i]%mod;
// for(int j=1;j<=i;j++)
// ef02[i]=(ef02[i]+1ll*f02[j]*ef1f0[i-j])%mod;
// for(int j=0;j<=i;j++)
// f0[i+1]=(f0[i+1]+1ll*(ef1[j]-ef1f0[j])*ivf0[i-j])%mod;
// for(int j=0;j<=i;j++)
// f1[i+1]=(f1[i+1]+1ll*(ef1[j]-ef02[j])*ivf0[i-j])%mod;
// red(f0[i+1]); red(f1[i+1]);
// printf("%d: %d %d %d %d %d %d %d\n",i,f0[i],f1[i],f02[i],ivf0[i],ef1[i],ef1f0[i],ef02[i]);
// }
printf("%lld\n",1ll*add(f1[n],f0[n])*fac[n]%mod);
// fprintf(stderr,"%lf\n",clock()/(double)CLOCKS_PER_SEC);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 12204kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 6ms
memory: 12080kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #3:
score: 0
Accepted
time: 5ms
memory: 12036kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #4:
score: 0
Accepted
time: 10ms
memory: 12036kb
input:
100
output:
413875584
result:
ok 1 number(s): "413875584"
Test #5:
score: 0
Accepted
time: 9ms
memory: 12008kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 5ms
memory: 12176kb
input:
2
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 10ms
memory: 12076kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #8:
score: 0
Accepted
time: 6ms
memory: 12180kb
input:
4
output:
236
result:
ok 1 number(s): "236"
Test #9:
score: 0
Accepted
time: 9ms
memory: 12076kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #10:
score: 0
Accepted
time: 6ms
memory: 12180kb
input:
6
output:
55182
result:
ok 1 number(s): "55182"
Test #11:
score: 0
Accepted
time: 6ms
memory: 12188kb
input:
7
output:
1165220
result:
ok 1 number(s): "1165220"
Test #12:
score: 0
Accepted
time: 0ms
memory: 12220kb
input:
8
output:
29013896
result:
ok 1 number(s): "29013896"
Test #13:
score: 0
Accepted
time: 10ms
memory: 12036kb
input:
9
output:
832517514
result:
ok 1 number(s): "832517514"
Test #14:
score: 0
Accepted
time: 10ms
memory: 12104kb
input:
10
output:
96547079
result:
ok 1 number(s): "96547079"
Test #15:
score: 0
Accepted
time: 9ms
memory: 12080kb
input:
11
output:
296100513
result:
ok 1 number(s): "296100513"
Test #16:
score: 0
Accepted
time: 6ms
memory: 12212kb
input:
12
output:
672446962
result:
ok 1 number(s): "672446962"
Test #17:
score: 0
Accepted
time: 9ms
memory: 12156kb
input:
13
output:
986909297
result:
ok 1 number(s): "986909297"
Test #18:
score: 0
Accepted
time: 3ms
memory: 12180kb
input:
14
output:
306542229
result:
ok 1 number(s): "306542229"
Test #19:
score: 0
Accepted
time: 0ms
memory: 12224kb
input:
15
output:
8548107
result:
ok 1 number(s): "8548107"
Test #20:
score: 0
Accepted
time: 4ms
memory: 12148kb
input:
16
output:
773960239
result:
ok 1 number(s): "773960239"
Test #21:
score: 0
Accepted
time: 3ms
memory: 12132kb
input:
17
output:
611627547
result:
ok 1 number(s): "611627547"
Test #22:
score: 0
Accepted
time: 3ms
memory: 12180kb
input:
18
output:
91793980
result:
ok 1 number(s): "91793980"
Test #23:
score: 0
Accepted
time: 6ms
memory: 12180kb
input:
19
output:
689202618
result:
ok 1 number(s): "689202618"
Test #24:
score: 0
Accepted
time: 5ms
memory: 12144kb
input:
20
output:
605957782
result:
ok 1 number(s): "605957782"
Test #25:
score: 0
Accepted
time: 101ms
memory: 13088kb
input:
10000
output:
713782215
result:
ok 1 number(s): "713782215"
Test #26:
score: 0
Accepted
time: 222ms
memory: 14208kb
input:
20000
output:
337916836
result:
ok 1 number(s): "337916836"
Test #27:
score: 0
Accepted
time: 222ms
memory: 14136kb
input:
30000
output:
580803285
result:
ok 1 number(s): "580803285"
Test #28:
score: 0
Accepted
time: 506ms
memory: 16116kb
input:
40000
output:
732660392
result:
ok 1 number(s): "732660392"
Test #29:
score: 0
Accepted
time: 493ms
memory: 16004kb
input:
50000
output:
660835595
result:
ok 1 number(s): "660835595"
Test #30:
score: 0
Accepted
time: 491ms
memory: 16152kb
input:
60000
output:
323452070
result:
ok 1 number(s): "323452070"
Test #31:
score: 0
Accepted
time: 1117ms
memory: 20124kb
input:
70000
output:
307315915
result:
ok 1 number(s): "307315915"
Test #32:
score: 0
Accepted
time: 1110ms
memory: 20028kb
input:
80000
output:
951757567
result:
ok 1 number(s): "951757567"
Test #33:
score: 0
Accepted
time: 1102ms
memory: 20112kb
input:
90000
output:
426123208
result:
ok 1 number(s): "426123208"
Test #34:
score: 0
Accepted
time: 1192ms
memory: 20032kb
input:
100000
output:
827418228
result:
ok 1 number(s): "827418228"
Test #35:
score: 0
Accepted
time: 1431ms
memory: 20036kb
input:
110000
output:
541614559
result:
ok 1 number(s): "541614559"
Test #36:
score: 0
Accepted
time: 1345ms
memory: 20052kb
input:
120000
output:
184688986
result:
ok 1 number(s): "184688986"
Test #37:
score: 0
Accepted
time: 1087ms
memory: 20020kb
input:
130000
output:
898089371
result:
ok 1 number(s): "898089371"
Test #38:
score: 0
Accepted
time: 2491ms
memory: 27908kb
input:
140000
output:
949540221
result:
ok 1 number(s): "949540221"
Test #39:
score: 0
Accepted
time: 2521ms
memory: 28028kb
input:
150000
output:
767689851
result:
ok 1 number(s): "767689851"
Test #40:
score: 0
Accepted
time: 2518ms
memory: 27968kb
input:
160000
output:
553494563
result:
ok 1 number(s): "553494563"
Test #41:
score: 0
Accepted
time: 2477ms
memory: 27964kb
input:
170000
output:
270711750
result:
ok 1 number(s): "270711750"
Test #42:
score: 0
Accepted
time: 2499ms
memory: 28096kb
input:
180000
output:
108155689
result:
ok 1 number(s): "108155689"
Test #43:
score: 0
Accepted
time: 2466ms
memory: 28052kb
input:
190000
output:
327542856
result:
ok 1 number(s): "327542856"
Test #44:
score: 0
Accepted
time: 2524ms
memory: 28088kb
input:
200000
output:
236144151
result:
ok 1 number(s): "236144151"
Test #45:
score: 0
Accepted
time: 2449ms
memory: 27948kb
input:
198798
output:
16935264
result:
ok 1 number(s): "16935264"
Extra Test:
score: 0
Extra Test Passed