QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379952#8329. Excusebachbeo2007AC ✓475ms16632kbC++233.6kb2024-04-06 20:12:052024-04-06 20:12:06

Judging History

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

  • [2024-04-06 20:12:06]
  • 评测
  • 测评结果:AC
  • 用时:475ms
  • 内存:16632kb
  • [2024-04-06 20:12:05]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=200005;
const int B=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;

void fft(vector<int> &a,bool invert){
    int n=(int)a.size();
    for(int i=1,j=0;i<n;i++){
        int bit=n>>1;
        while(j&bit){j^=bit;bit>>=1;}
        j^=bit;
        if(i<j) swap(a[i],a[j]);
    }
    for(int len=2;len<=n;len<<=1){
        int wn=power((invert?iroot:root),(mod-1)/len);
        for(int i=0;i<n;i+=len){
            int w=1;
            for(int j=0;j<len/2;j++){
                int u=a[i+j],v=a[i+j+len/2]*w%mod;
                a[i+j]=(u+v)%mod;
                a[i+j+len/2]=(u-v+mod)%mod;
                w=w*wn%mod;
            }
        }
    }
    if(invert){
        int dd=power(n,mod-2);
        for(int i=0;i<n;i++) a[i]=a[i]*dd%mod;
    }
    return;
}

vector<int> mul(vector<int> a,vector<int> b){
    int n=(int)a.size()+(int)b.size(),sz=1;
    while(sz<n) sz<<=1;
    a.resize(sz);b.resize(sz);
    fft(a,false);fft(b,false);
    for(int i=0;i<sz;i++) a[i]=a[i]*b[i]%mod;
    fft(a,true);
    return a;
}

int fac[maxn],dfac[maxn],inv[maxn];
int C(int n,int k){
    if(k>n || k<0 || n<0) return 0;
    return fac[n]*dfac[k]%mod*dfac[n-k]%mod;
}
void combi(int n){
    fac[0]=inv[0]=1;
    for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
    dfac[n]=power(fac[n],mod-2);
    for(int i=n;i>=1;i--){
        dfac[i-1]=dfac[i]*i%mod;
        inv[i]=dfac[i]*fac[i-1]%mod;
    }
}
int dp[maxn],inv2[maxn];

void dnc(int l,int r){
    if(l==r){
        dp[l]=dp[l]*inv2[l]%mod*fac[l]%mod;
        return;
    }
    int mid=(l+r)>>1;
    dnc(l,mid);
    vector<int> a(mid-l+1),b(r-l+1);
    for(int i=l;i<=mid;i++) a[i-l]=(dp[i]+1)*dfac[i]%mod;
    for(int i=0;i<=r-l;i++) b[i]=dfac[i]%mod;
    a=mul(a,b);
    for(int i=mid+1;i<=r;i++) dp[i]=(dp[i]+a[i-l])%mod;
    dnc(mid+1,r);
}

void solve(){
    int n;cin >> n;combi(n);
    inv2[0]=1;
    for(int i=1;i<=n;i++) inv2[i]=inv2[i-1]*((mod+1)/2)%mod;
    dnc(0,n);
    cout << dp[n] << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1

output:

499122177

result:

ok 1 number(s): "499122177"

Test #2:

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

input:

3

output:

561512450

result:

ok 1 number(s): "561512450"

Test #3:

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

input:

10

output:

609769250

result:

ok 1 number(s): "609769250"

Test #4:

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

input:

1000

output:

475714976

result:

ok 1 number(s): "475714976"

Test #5:

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

input:

1024

output:

178624793

result:

ok 1 number(s): "178624793"

Test #6:

score: 0
Accepted
time: 475ms
memory: 15084kb

input:

100000

output:

537516197

result:

ok 1 number(s): "537516197"

Test #7:

score: 0
Accepted
time: 469ms
memory: 15548kb

input:

99471

output:

489775976

result:

ok 1 number(s): "489775976"

Test #8:

score: 0
Accepted
time: 230ms
memory: 13560kb

input:

65536

output:

171446457

result:

ok 1 number(s): "171446457"

Test #9:

score: 0
Accepted
time: 259ms
memory: 12924kb

input:

84792

output:

371578800

result:

ok 1 number(s): "371578800"

Test #10:

score: 0
Accepted
time: 468ms
memory: 16632kb

input:

93846

output:

841905002

result:

ok 1 number(s): "841905002"

Extra Test:

score: 0
Extra Test Passed