QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236424#7632. Balanced Arraysucup-team870AC ✓204ms54148kbC++203.3kb2023-11-03 22:43:592023-11-03 22:44:00

Judging History

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

  • [2023-11-03 22:44:00]
  • 评测
  • 测评结果:AC
  • 用时:204ms
  • 内存:54148kb
  • [2023-11-03 22:43:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,l,r) for(int i=(l); i<=(r); i++)
#define per(i,r,l) for(int i=(r); i>=(l); i--)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
const int N =5e5+5, mod =998244353, G = 3;
ll qp(ll x, ll y) {
    ll res = 1;
    while (y) {
        if (y & 1)res = res * x % mod;
        x = x * x % mod; y >>= 1;
    }return res;
}
const int Gi = qp(G, mod - 2);
namespace Poly {
    typedef vi poly;
    int limit = 1, L = 0; int r[N * 4];
    void NTT(poly& A, int type) { //下标在[0,limit)范围内,数组开四倍即可
        A.resize(limit);
        for (int i = 0; i < limit; i++)
            if (i < r[i]) swap(A[i], A[r[i]]);
        for (int mid = 1; mid < limit; mid <<= 1) {
            ll Wn = qp(type == 1 ? G : Gi, (mod - 1) / (mid << 1)); //G是模数的原根,Gi是逆元
            for (int j = 0; j < limit; j += (mid << 1)) {
                ll w = 1; //ll不一定够
                for (int k = 0; k < mid; k++, w = (w * Wn) % mod) {
                    int x = A[j + k], y = w * A[j + k + mid] % mod; //int不一定够
                    A[j + k] = (x + y) % mod, A[j + k + mid] = (x - y + mod) % mod;
                }
            }
        }
    }
    poly operator + (poly a, poly b) {
        int n = max(a.size(), b.size());
        a.resize(n); b.resize(n);
        rep(i, 0, n - 1)a[i] = (a[i] + b[i]) % mod;
        return a;
    }
    poly operator - (poly a, poly b) {
        int n = max(a.size(), b.size());
        a.resize(n); b.resize(n);
        rep(i, 0, n - 1)a[i] = (a[i] - b[i] + mod) % mod;
        return a;
    }
    void poly_mul_init(poly& a, poly& b) {
        limit = 1; L = 0;
        int N = a.size() - 1, M = b.size() - 1;
        while (limit <= N + M) limit <<= 1, L++;
        rep(i, 0, limit - 1)r[i] = (r[i >> 1] >> 1) | ((i & 1) << (L - 1));
    }
    poly poly_mul(poly a, poly b) { //原先的a,b不需要维持原状的话,可以加&
        int n = a.size() + b.size() - 1;
        poly_mul_init(a, b);
        NTT(a, 1); NTT(b, 1);
        rep(i, 0, limit - 1)a[i] = 1ll * a[i] * b[i] % mod; //a[i]为ll不一定够
        NTT(a, -1);
        ll INV = qp(limit, mod - 2);
        rep(i, 0, limit - 1)a[i] = a[i] * INV % mod;
        a.resize(n); return a;
    }
}
signed main(){
    IOS
    const int M=2e6;
    vector<ll>fac(M+1),inv(M+1);
    fac[0]=1; rep(i,1,M)fac[i]=i*fac[i-1]%mod;
    inv[M]=qp(fac[M],mod-2); per(i,M,1)inv[i-1]=inv[i]*i%mod;
    int n,m; cin>>n>>m;
    vi fc(m+1),fd(m+1);
    auto p2=[&](ll x){
        return x*x%mod;
    };
    rep(c,1,m){
        if(n+1-2*c<0)break;
        fc[c]=inv[c]*inv[c-1]%mod*inv[n+1-2*c]%mod;
    }
    rep(d,0,m)fd[d]=fac[n+1+2*d]*inv[d]%mod*inv[d+1]%mod;
    auto res=Poly::poly_mul(fc,fd);
    ll ans=1;
    // auto C=[&](int i,int j){
    //     if(i<j)return 0ll;
    //     return fac[i]*inv[j]%mod*inv[i-j]%mod;
    // };
    rep(k,1,m){
        ans=(ans + fac[k-1]*fac[k]%mod*inv[2*k]%mod*res[k])%mod;
        // rep(c,1,k) {
        //     ans=(ans+ C(n+1-2*c+2*k,2*k)*p2(C(k-1,c-1))%mod*qp(1,mod-2) )%mod;
        //     // cout<<c<<' '<<k<<" "<<p2(C(k-1,c-1))%mod*qp(1,mod-2)%mod<<endl;
        // }
    }
    cout<<ans<<'\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 17ms
memory: 34380kb

input:

2 2

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 196ms
memory: 53584kb

input:

500000 500000

output:

984531374

result:

ok 1 number(s): "984531374"

Test #3:

score: 0
Accepted
time: 15ms
memory: 34296kb

input:

500000 1

output:

219705876

result:

ok 1 number(s): "219705876"

Test #4:

score: 0
Accepted
time: 199ms
memory: 54036kb

input:

1 500000

output:

500001

result:

ok 1 number(s): "500001"

Test #5:

score: 0
Accepted
time: 196ms
memory: 52324kb

input:

500000 353535

output:

33730077

result:

ok 1 number(s): "33730077"

Test #6:

score: 0
Accepted
time: 201ms
memory: 53540kb

input:

353535 500000

output:

182445298

result:

ok 1 number(s): "182445298"

Test #7:

score: 0
Accepted
time: 194ms
memory: 53808kb

input:

499999 499999

output:

933220940

result:

ok 1 number(s): "933220940"

Test #8:

score: 0
Accepted
time: 190ms
memory: 54148kb

input:

499999 499998

output:

899786345

result:

ok 1 number(s): "899786345"

Test #9:

score: 0
Accepted
time: 200ms
memory: 51528kb

input:

377773 400009

output:

206748715

result:

ok 1 number(s): "206748715"

Test #10:

score: 0
Accepted
time: 51ms
memory: 39800kb

input:

499999 100001

output:

482775773

result:

ok 1 number(s): "482775773"

Test #11:

score: 0
Accepted
time: 189ms
memory: 52704kb

input:

444445 488884

output:

70939759

result:

ok 1 number(s): "70939759"

Test #12:

score: 0
Accepted
time: 196ms
memory: 52080kb

input:

488885 444449

output:

591315327

result:

ok 1 number(s): "591315327"

Test #13:

score: 0
Accepted
time: 18ms
memory: 34244kb

input:

500000 111

output:

313439156

result:

ok 1 number(s): "313439156"

Test #14:

score: 0
Accepted
time: 197ms
memory: 52520kb

input:

333333 444444

output:

403492103

result:

ok 1 number(s): "403492103"

Test #15:

score: 0
Accepted
time: 199ms
memory: 50904kb

input:

499994 343433

output:

334451699

result:

ok 1 number(s): "334451699"

Test #16:

score: 0
Accepted
time: 197ms
memory: 52736kb

input:

477774 411113

output:

63883341

result:

ok 1 number(s): "63883341"

Test #17:

score: 0
Accepted
time: 191ms
memory: 52444kb

input:

123456 432109

output:

238795570

result:

ok 1 number(s): "238795570"

Test #18:

score: 0
Accepted
time: 189ms
memory: 53596kb

input:

131331 467777

output:

834790039

result:

ok 1 number(s): "834790039"

Test #19:

score: 0
Accepted
time: 18ms
memory: 34176kb

input:

500000 2

output:

304727284

result:

ok 1 number(s): "304727284"

Test #20:

score: 0
Accepted
time: 17ms
memory: 34224kb

input:

1111 111

output:

98321603

result:

ok 1 number(s): "98321603"

Test #21:

score: 0
Accepted
time: 196ms
memory: 52648kb

input:

416084 493105

output:

916827025

result:

ok 1 number(s): "916827025"

Test #22:

score: 0
Accepted
time: 107ms
memory: 43884kb

input:

53888 138663

output:

57263952

result:

ok 1 number(s): "57263952"

Test #23:

score: 0
Accepted
time: 198ms
memory: 52772kb

input:

219161 382743

output:

304889787

result:

ok 1 number(s): "304889787"

Test #24:

score: 0
Accepted
time: 199ms
memory: 52140kb

input:

181392 318090

output:

12528742

result:

ok 1 number(s): "12528742"

Test #25:

score: 0
Accepted
time: 196ms
memory: 52116kb

input:

135930 422947

output:

554153000

result:

ok 1 number(s): "554153000"

Test #26:

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

input:

280507 210276

output:

812816587

result:

ok 1 number(s): "812816587"

Test #27:

score: 0
Accepted
time: 204ms
memory: 53520kb

input:

253119 420465

output:

124024302

result:

ok 1 number(s): "124024302"

Test #28:

score: 0
Accepted
time: 55ms
memory: 38604kb

input:

446636 97448

output:

150388382

result:

ok 1 number(s): "150388382"

Test #29:

score: 0
Accepted
time: 58ms
memory: 38780kb

input:

284890 126665

output:

786559507

result:

ok 1 number(s): "786559507"

Test #30:

score: 0
Accepted
time: 26ms
memory: 37480kb

input:

186708 28279

output:

607509026

result:

ok 1 number(s): "607509026"

Extra Test:

score: 0
Extra Test Passed