QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708404#8834. Formal Fringucup-team134#AC ✓124ms95324kbC++141.7kb2024-11-03 22:01:062024-11-03 22:01:07

Judging History

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

  • [2024-11-03 22:01:07]
  • 评测
  • 测评结果:AC
  • 用时:124ms
  • 内存:95324kb
  • [2024-11-03 22:01:06]
  • 提交

answer

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

#define ll long long
const int mod=998244353;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int sub(int x,int y){x-=y;return x<0?x+mod:x;}
int mul(int x,int y){return (ll)x*y%mod;}
int powmod(int x,int k){
    int ans=1;
    for(;k;k>>=1,x=mul(x,x))if(k&1)ans=mul(ans,x);
    return ans;
}

const int N=1000050;
const int L=21;
int dp[2][N],now=1,pre=0;
int one[L][N],all[L],suff[N];
void Calc(){
    dp[now][0]=1;
    for(int j=0;j<L;j++){
        swap(pre,now);
        vector<int> sum(1<<j,0);
        for(int i=0;i<N;i++){
            sum[i%(1<<j)]=add(sum[i%(1<<j)],dp[pre][i]);
            dp[now][i]=sum[i%(1<<j)];
        }
    }

    one[0][1]=1;
    all[0]=1;
    suff[N-1]=one[0][N-1];
    for(int i=N-2;i>=0;i--)suff[i]=add(suff[i+1],one[0][i]);
    for(int j=1;j<L;j++){
        for(int i=3;i<N;i+=2){
            int taken=(i-1)/2;
            one[j][i]=suff[taken];
            /*for(int last=taken;last<N;last++){
                one[j][i]=add(one[j][i],one[j-1][last]);
            }*/
            all[j]=add(all[j],one[j][i]);
        }
        suff[N-1]=one[j][N-1];
        for(int i=N-2;i>=0;i--)suff[i]=add(suff[i+1],one[j][i]);
    }
}

int main(){
    int n;
    scanf("%i",&n);
    Calc();
    for(int x=1;x<=n;x++){
        int mxb=-1;
        for(int i=0;i<L;i++){
            if(x>>i&1)mxb=i;
        }
        int cnt=0;
        int tmp=x;
        int ans=0;
        while(mxb>=0 && (x>>mxb&1)){
            tmp-=(1<<mxb);
            ans=add(ans,mul(all[cnt],dp[now][tmp]));
            mxb--;
            cnt++;
        }
        printf("%i ",ans);
    }
    printf("\n");
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 78ms
memory: 93888kb

input:

10

output:

1 1 2 1 1 3 6 1 1 2 

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 62ms
memory: 94580kb

input:

70

output:

1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6 

result:

ok 70 numbers

Test #3:

score: 0
Accepted
time: 124ms
memory: 95324kb

input:

1000000

output:

1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 36 36 46 46 60 60 74 74 94 94 114 114 140 140 166 166 203 203 240 240 288 288 336 336 400 ...

result:

ok 1000000 numbers

Extra Test:

score: 0
Extra Test Passed