QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402004#8543. Periodic SequenceWilliamxzhAC ✓875ms13348kbC++141.9kb2024-04-29 18:50:152024-04-29 18:50:15

Judging History

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

  • [2024-04-29 18:50:15]
  • 评测
  • 测评结果:AC
  • 用时:875ms
  • 内存:13348kb
  • [2024-04-29 18:50:15]
  • 提交

answer


#include <bits/stdc++.h>
#define il inline
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll mod,f[N],g[N],a[N],fac[N],inv[N],pw[N];int n,m;
il ll qp(ll a,ll b){
    ll ans=1ll;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod,b>>=1;
    }
    return ans;
}
il void add(ll &x,ll y){x=(x+y>=mod?x+y-mod:x+y);}
il ll ad(ll x,ll y){return (x+y>=mod?x+y-mod:x+y);}
il void del(ll &x,ll y){x=(x<y?x-y+mod:x-y);}
il ll C(int n,int m){return (n<0 || m<0 || n<m)?0ll:(fac[n]*inv[m]%mod*inv[n-m])%mod;}
il void init(){
    ll x,y,z,u,v,w;
    m=sqrtl(n);fac[0]=pw[0]=1ll;
    for(int i=1;i<=n;++i) fac[i]=(fac[i-1]*1ll*i)%mod,pw[i]=(pw[i-1]*2ll)%mod;
    inv[n]=qp(fac[n],mod-2ll);for(int i=n-1;i>=0;--i) inv[i]=(inv[i+1]*(i+1ll))%mod;
    for(int i=1;i<=m;++i){
        g[i]=1ll,x=1ll,add(f[i],g[i]);
        for(int j=i+1;j<=n;++j){
            if(j>=i*2+1) del(x,g[j-i-1]);
            g[j]=x,add(f[j],g[j]);
            add(x,g[j]);
        }
    }
    for(int t=0;t+(m+1)<=n;++t){
        if(t==0) x=1;else x=pw[t-1];
        add(a[t+(m+1)],x);
    }
    for(int i=1;i<=n;++i) add(a[i],a[i-1]);
    for(int i=1;i<=n;++i) add(f[i],a[i]);
    for(int l=1;l<=m;++l){
        for(int i=0;i<=n;++i) a[i]=0ll;
        if(l&1) del(a[l+(m+1)*(l+1)],1ll);else add(a[l+(m+1)*(l+1)],1ll);
        x=fac[l-1]*inv[l]%mod;int k=n-(m+1)*(l+1);
        for(int t=k;t>l;--t){
            //x=C(t-1,l)*pw[t-l-1]%mod,y=C(t-1,l-1)*pw[t-l]%mod;
            //z=ad(x,y);if(l&1) z=mod-z;
            y=(fac[t-1]*(t+l)%mod*inv[l]%mod*inv[t-l])%mod;
            z=y*pw[t-l-1]%mod;if(l&1) z=mod-z;
            add(a[t+(m+1)*(l+1)],z);
        }
        for(int i=l+1;i<=n;++i) add(a[i],a[i-l-1]);
        for(int i=1;i<=n;++i) add(f[i],a[i]);
    }
    for(int i=1;i<=n;++i) f[i]=(f[i-1]+f[i])%mod;
}
int T;
int main(){
    scanf("%d%lld",&n,&mod);init();
    for(int i=1;i<=n;++i) printf("%lld ",f[i]);
    return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3852kb

input:

5 1000000007

output:

1 3 6 11 19 

result:

ok 5 number(s): "1 3 6 11 19"

Test #2:

score: 0
Accepted
time: 873ms
memory: 13132kb

input:

200000 567894337

output:

1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 195106662 344669981 35619335 477103886 79913732 147415830 329955039 273123672 546045352 337527455 443978690 4597...

result:

ok 200000 numbers

Test #3:

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

input:

2000 1000000009

output:

1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 480458646 875091002 588152874 869906045 159506110 218346934 346224469 716986623 864678016 300921504 68...

result:

ok 2000 numbers

Test #4:

score: 0
Accepted
time: 874ms
memory: 13320kb

input:

200000 998244853

output:

1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 482213802 878601314 596928654 887457605 196364386 290308330 486636949 990790959 401755743 350504783 12...

result:

ok 200000 numbers

Test #5:

score: 0
Accepted
time: 875ms
memory: 13184kb

input:

200000 1000000009

output:

1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 480458646 875091002 588152874 869906045 159506110 218346934 346224469 716986623 864678016 300921504 68...

result:

ok 200000 numbers

Test #6:

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

input:

1 998244853

output:

1 

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 371ms
memory: 9304kb

input:

114514 1009999999

output:

1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 470458656 855091022 538152924 769906145 959506319 818347343 556225268 166988182 844681063 390927468 51...

result:

ok 114514 numbers

Test #8:

score: 0
Accepted
time: 874ms
memory: 13348kb

input:

199998 500000003

output:

1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 263000996 480458649 375091005 88152886 369906072 159506173 218347057 346224709 216987088 364678928 300923295 688...

result:

ok 199998 numbers

Extra Test:

score: 0
Extra Test Passed