QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#348577#8329. Excuseucup-team206#AC ✓352ms25888kbC++172.1kb2024-03-09 19:42:142024-03-09 19:42:15

Judging History

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

  • [2024-03-09 19:42:15]
  • 评测
  • 测评结果:AC
  • 用时:352ms
  • 内存:25888kb
  • [2024-03-09 19:42:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef long long ll;
const int N=4e5+50;
const int Mod=998244353;
ll Fast(ll x,int b) {
    ll t=1;
    for(; b; b>>=1,x=x*x%Mod) if(b&1) t=t*x%Mod;
    return t;
}
typedef vector<ll> Poly;
void NTT(Poly &A,int f) {
    static int rev[N];
    static ll w[N],a[N];
    int n=A.size();
    FOR(i,1,n-1) rev[i]=(rev[i>>1]>>1)|((i&1)*(n>>1));
    FOR(i,0,n-1) a[rev[i]]=A[i];
    w[0]=1,w[1]=Fast(f>0?3:Fast(3,Mod-2),(Mod-1)/n);
    FOR(i,2,n-1) w[i]=w[i-1]*w[1]%Mod;
    for(int l=2; l<=n; l<<=1) 
        for(ll *p=a,m=l>>1; p<a+n; p+=l) {
            FOR(i,0,m-1) {
                ll t=p[i+m];
                p[i+m]=(p[i]+w[n/l*(i+m)]*t)%Mod;
                p[i]=(p[i]+w[n/l*i]*t)%Mod;
            }
        }
    ll t=f>0?1:Fast(n,Mod-2);
    FOR(i,0,n-1) A[i]=a[i]*t%Mod;
}
Poly operator *(Poly a,Poly b) {
    int n=1,m=a.size()+b.size()-1;
    for(; n<m; n<<=1);
    a.resize(n,0),NTT(a,1);
    b.resize(n,0),NTT(b,1);
    FOR(i,0,n-1) a[i]=a[i]*b[i]%Mod;
    return NTT(a,-1),a.resize(m),a;
}
ll f[N];
ll Fac[N],Inv[N];
ll C(int n,int m) {
    return Fac[n]*Inv[m]%Mod*Inv[n-m]%Mod;
}
void solve(int L,int R) {
    if(L==R) {
        f[L]=f[L]*Fac[L]%Mod*Fast(Fast(2,L),Mod-2)%Mod;
        return ;
    }
    int mid=L+R>>1;
    solve(L,mid);
    Poly a,b;
    FOR(i,L,mid) a.push_back((f[i]+1)*Inv[i]%Mod);
    FOR(i,1,R-L) b.push_back(Inv[i]);
    a=a*b;
    FOR(i,mid+1,R) {
        f[i]=(f[i]+a[i-L-1])%Mod;
    }
    solve(mid+1,R);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    Fac[0]=1;
    FOR(i,1,n) Fac[i]=Fac[i-1]*i%Mod;
    Inv[n]=Fast(Fac[n],Mod-2);
    DOR(i,n,1) Inv[i-1]=Inv[i]*i%Mod;
    // f[0]=0;
    // FOR(i,1,n) {
    //     FOR(j,1,i) {
    //         f[i]=(f[i]+C(i,j)*(f[i-j]+1))%Mod;
    //     }
    //     f[i]=f[i]*Fast(Fast(2,i),Mod-2)%Mod;
    // }
    // cout << f[n] << '\n';
    solve(0,n);
    cout << f[n] << '\n';
    return 0;
}

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

詳細信息

Test #1:

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

input:

1

output:

499122177

result:

ok 1 number(s): "499122177"

Test #2:

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

input:

3

output:

561512450

result:

ok 1 number(s): "561512450"

Test #3:

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

input:

10

output:

609769250

result:

ok 1 number(s): "609769250"

Test #4:

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

input:

1000

output:

475714976

result:

ok 1 number(s): "475714976"

Test #5:

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

input:

1024

output:

178624793

result:

ok 1 number(s): "178624793"

Test #6:

score: 0
Accepted
time: 352ms
memory: 21832kb

input:

100000

output:

537516197

result:

ok 1 number(s): "537516197"

Test #7:

score: 0
Accepted
time: 352ms
memory: 25888kb

input:

99471

output:

489775976

result:

ok 1 number(s): "489775976"

Test #8:

score: 0
Accepted
time: 161ms
memory: 21540kb

input:

65536

output:

171446457

result:

ok 1 number(s): "171446457"

Test #9:

score: 0
Accepted
time: 186ms
memory: 20196kb

input:

84792

output:

371578800

result:

ok 1 number(s): "371578800"

Test #10:

score: 0
Accepted
time: 331ms
memory: 23168kb

input:

93846

output:

841905002

result:

ok 1 number(s): "841905002"

Extra Test:

score: 0
Extra Test Passed