QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765705#8834. Formal FringFido_PuppyAC ✓89ms82916kbC++231.9kb2024-11-20 15:03:052024-11-20 15:03:05

Judging History

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

  • [2024-11-20 15:03:05]
  • 评测
  • 测评结果:AC
  • 用时:89ms
  • 内存:82916kb
  • [2024-11-20 15:03:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pr pair<int, int>
#define pb push_back
#define mid (l + r) / 2
#define ls num << 1
#define rs num << 1 | 1

inline int read() {
    int x = 0, m = 1;
    char ch = getchar();

    while (!isdigit(ch)) {
        if (ch == '-') m = -1;
        ch = getchar();
    }

    while (isdigit(ch)) {
        x = x * 10 + ch - 48;
        ch = getchar();
    }

    return x * m;
}

inline void write(int x) {
    if (x < 0) {
        putchar('-');
        write(-x);
        return;
    }

    if (x >= 10) write(x / 10);
    putchar(x % 10 + '0');
}

const int N = 1e6 + 5, M = 20, mod = 998244353;

int add(int x, int y) {
    return (x + y >= mod) ? (x + y - mod) : (x + y);
}

int sub(int x, int y) {
    return (x - y < 0) ? (x - y + mod) : (x - y);
}

void Add(int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

void Sub(int &x, int y) {
    x -= y;
    if (x < 0) x += mod;
}

int ans[N], f[N][M], g[M];

signed main() {
    int n = read(), m = 0;
    for (int i = 0; i < 20; i++) f[0][i] = 1;
    g[0] = 1;
    for (int i = 1; i <= n; i++) {
        int sum = 0;
        for (int j = 0; j < 20; j++) {
            if ((1 << j) <= i) Add(sum, f[i - (1 << j)][j]);
            f[i][j] = sum;
        }
        if ((i + 3) == ((i + 3) & (-(i + 3)))) {
            m++;
            g[m] = f[i][19];
            for (int j = 0; j < m - 1; j++) {
                Sub(g[m], 1ll * g[j] * f[(1 << (m + 1)) - 1 - (((1 << (j + 1)) - 1) << (m - j)) - 2][m - j] % mod);
            }
        }
        int x = 0, ans = 0, lim = 0;
        for (int j = __lg(i); j >= 0; j--) {
            if ((i >> j) & 1) {
                lim = lim << 1 | 1;
                Add(ans, 1ll * f[i - (lim << j)][19] * g[x] % mod);
                x++;
            }
            else break;
        }
        write(ans);
        putchar(" \n"[i == n]);
    }
}

详细

Test #1:

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

input:

10

output:

1 1 2 1 1 3 6 1 1 2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3660kb

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: 89ms
memory: 82916kb

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