QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471562#8834. Formal Fringucup-team3519#AC ✓269ms120316kbC++202.1kb2024-07-10 22:11:312024-07-10 22:11:31

Judging History

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

  • [2024-07-10 22:11:31]
  • 评测
  • 测评结果:AC
  • 用时:269ms
  • 内存:120316kb
  • [2024-07-10 22:11:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back


typedef long long LL;
typedef pair<int, int> pi;

const int mod = 998244353;

void solve() {
    int n; cin >> n;
    const int to = 1e6;
    V<V<int>> f(to + 1, V<int>(22));
    for(auto &y : f[0]) y = 1;
    for(int i = 1; i <= to; i++) {
        for(int j = 0; j < 22; j++) {
            if(j) f[i][j] += f[i][j - 1];
            if(f[i][j] >= mod) f[i][j] -= mod;
            if(i - (1 << j) >= 0) f[i][j] += f[i - (1 << j)][j];
            if(f[i][j] >= mod) f[i][j] -= mod;

        }
    }

    V<V<int>> dp(20);
    for(int i = 1; i <= 19; i++) {
        dp[i].resize(i + 1);
        for(int bit = 0; bit < 1 << i; bit++) {
            int t = 1;
            int lst = 0;
            LL cur = 1;
            for(int j = 0; j < i; j++) {
                if(bit >> j & 1) {
                    // t *= -1;
                    cur *= -1;
                    cur = cur * f[(1 << j - lst + 1) - 1][21] % mod;
                    lst = j + 1;
                }
            }
            dp[i][i - lst] += cur;
            if(dp[i][i - lst] >= mod) dp[i][i - lst] -= mod;
            if(dp[i][i - lst] < 0) dp[i][i - lst] += mod;
        }
    }

    // for(int i = 1; i <= 10; i++) {
    //     for(int j = 0; j <= i; j++) {
    //         cout << dp[i][j] << " \n"[j == i];
    //     }
    // }


    // for(int i = 1; i <= n; i++) cout << dp[i][22]
    for(int i = 1; i <= n; i++) {
        int hi = __lg(i);
        int lo = hi;
        while(lo && (i >> lo - 1 & 1)) lo--;
        int cnt = hi - lo + 1;
        //dp[cnt];
        LL cur = i;
        LL ans = 0;
        for(int i = hi; i >= lo - 1; i--) {
            ans += 1LL * dp[cnt][i - lo + 1] * f[cur][21] % mod;
            if(ans >= mod) ans -= mod;

            //end
            if(i != lo - 1) cur -= 1 << i;
        }
        LL to_say = f[i][21] - ans;
        if(to_say < 0) to_say += mod;
        cout << to_say << " ";
    }

    
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    // int t; cin >> t;
    // while(t--) solve();
    solve();
}

详细

Test #1:

score: 100
Accepted
time: 214ms
memory: 120292kb

input:

10

output:

1 1 2 1 1 3 6 1 1 2 

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 221ms
memory: 120316kb

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: 269ms
memory: 120244kb

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