QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353705#8329. Excuseucup-team004#AC ✓1232ms16440kbC++203.0kb2024-03-14 15:14:412024-03-14 15:14:41

Judging History

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

  • [2024-03-14 15:14:41]
  • 评测
  • 测评结果:AC
  • 用时:1232ms
  • 内存:16440kb
  • [2024-03-14 15:14:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=300100;
const int mod=998244353;
typedef long long ll;

int ksm(ll a,int b,int c=1){
    for(;b;b/=2,a=a*a%mod)
        if(b&1)c=c*a%mod;
    return c;
}
int n_,lgn_,omg_[N],rev_[N],ww_[N];
void FFT_init(int n){
    for(lgn_=0;(1<<lgn_)<=n;++lgn_);
    n_=1<<lgn_;
    ll w=ksm(3,(mod-1)>>lgn_);
    omg_[0]=1;
    rev_[0]=0;
    for(int i=1;i<n_;++i){
        omg_[i]=omg_[i-1]*w%mod;
        rev_[i]=(rev_[i>>1]>>1)|((i&1)<<(lgn_-1));
    }
}

void DFT(int*a,int flag=0){
    for(int i=0;i<n_;++i)
        if(rev_[i]<i)
            swap(a[i],a[rev_[i]]);
    for(int i=0;i<lgn_;++i){
        int t=1<<i;
        for(int j=0;j<t;++j)
            ww_[j]=omg_[j<<(lgn_-i-1)];
        for(int j=0;j<n_;j+=t<<1){
            int*f=a+j,*g=a+j+t;
            for(int k=0;k<t;++k){
                int s=(ll)g[k]*ww_[k]%mod;
                g[k]=(f[k]-s+mod)%mod;
                f[k]=(f[k]+s)%mod;
            }
        }
    }
    if(flag){
        ll inv=mod-((mod-1)>>lgn_);
        reverse(a+1,a+n_);
        for(int i=0;i<n_;++i)
            a[i]=(ll)a[i]*inv%mod;
    }
}

int jc[N],jc2[N];
void Init(int n){
    jc[0]=1;
    for(int i=1;i<=n;++i)
        jc[i]=(ll)jc[i-1]*i%mod;
    jc2[n]=ksm(jc[n],mod-2);
    for(int i=n;i;--i)
        jc2[i-1]=(ll)jc2[i]*i%mod;
}


int n;

void modify(int*f,int*g,int x){
    int t=1;
    for(int i=0;i<=n;++i){
        g[i]=(ll)t*f[i]%mod;
        t=(ll)t*x%mod;
    }
}

int prod[N],sum[N],np[N],ns[N];

int e[N],e2[N];

void print(int*s=sum,int*p=prod){
}

void solve(int m){
    if(m==0)
        return;
    solve(m/2);
    memset(np,0,sizeof np);
    memset(ns,0,sizeof ns);
    int t=ksm(2,mod-1-m/2);
    modify(prod,np,t);
    modify(sum,ns,t);


    DFT(prod);
    DFT(sum);
    print();
    DFT(np);
    DFT(ns);
    print();

    for(int i=0;i<n_;++i){
        sum[i]=(sum[i]+(ll)prod[i]*ns[i])%mod;
        prod[i]=(ll)prod[i]*np[i]%mod;
    }

    DFT(sum,1);
    DFT(prod,1);

    for(int i=n+1;i<n_;++i)
        sum[i]=prod[i]=0;
    
    print();

    if(m&1){
        modify(sum,sum,(mod+1)/2);
        modify(prod,prod,(mod+1)/2);
        DFT(sum);
        DFT(prod);
        for(int i=0;i<n_;++i){
            sum[i]=((ll)sum[i]*e2[i]+e2[i])%mod;
            prod[i]=(ll)prod[i]*e2[i]%mod;
        }
        DFT(sum,1);
        DFT(prod,1);

        for(int i=n+1;i<n_;++i)
            sum[i]=prod[i]=0;
    }
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    Init(n);
    for(int i=1;i<=n;++i){
        e[i]=mod-jc2[i];
        if(i&1)
            e[i]=mod-e[i];
    }
    modify(e,e2,(mod+1)/2);
    for(int i=0;i<=n;++i)
        e[i]=jc2[i];
    FFT_init(2*n);
    DFT(e2);
    prod[0]=1;
    solve(n);
    DFT(sum);
    DFT(e);

    for(int i=0;i<n_;++i)
        sum[i]=(ll)sum[i]*e[i]%mod;
    
    DFT(sum,1);

    cout<<(ll)sum[n]*jc[n]%mod<<'\n';
    return 0;
}

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

详细

Test #1:

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

input:

1

output:

499122177

result:

ok 1 number(s): "499122177"

Test #2:

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

input:

3

output:

561512450

result:

ok 1 number(s): "561512450"

Test #3:

score: 0
Accepted
time: 2ms
memory: 13820kb

input:

10

output:

609769250

result:

ok 1 number(s): "609769250"

Test #4:

score: 0
Accepted
time: 6ms
memory: 15964kb

input:

1000

output:

475714976

result:

ok 1 number(s): "475714976"

Test #5:

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

input:

1024

output:

178624793

result:

ok 1 number(s): "178624793"

Test #6:

score: 0
Accepted
time: 1096ms
memory: 16100kb

input:

100000

output:

537516197

result:

ok 1 number(s): "537516197"

Test #7:

score: 0
Accepted
time: 1155ms
memory: 16148kb

input:

99471

output:

489775976

result:

ok 1 number(s): "489775976"

Test #8:

score: 0
Accepted
time: 917ms
memory: 16392kb

input:

65536

output:

171446457

result:

ok 1 number(s): "171446457"

Test #9:

score: 0
Accepted
time: 1159ms
memory: 16440kb

input:

84792

output:

371578800

result:

ok 1 number(s): "371578800"

Test #10:

score: 0
Accepted
time: 1232ms
memory: 16388kb

input:

93846

output:

841905002

result:

ok 1 number(s): "841905002"

Extra Test:

score: 0
Extra Test Passed