QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#458352 | #8834. Formal Fring | ucup-team180# | AC ✓ | 293ms | 175184kb | C++17 | 1.5kb | 2024-06-29 16:47:54 | 2024-06-29 16:47:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
int X;
cin >> X;
int LOG = 31 - __builtin_clz(X);
vector<vector<long long>> pre(LOG + 2, vector<long long>(X + 1, 0));
pre[0][0] = 1;
for (int i = 0; i <= LOG; i++){
pre[i + 1] = pre[i];
for (int j = 1 << i; j <= X; j++){
pre[i + 1][j] += pre[i + 1][j - (1 << i)];
pre[i + 1][j] %= MOD;
}
}
vector<long long> ans(X + 1, 0);
for (int i = 1; i <= X; i++){
int m = 31 - __builtin_clz(i);
if (i == (1 << (m + 1)) - 1){
ans[i] = pre[m + 1][i];
} else {
int L = max(1 << (m - 1), i - (1 << m) + 1);
int R = min(1 << m, i - (1 << (m - 1)) + 1);
vector<int> l(m + 1), r(m + 1);
l[0] = L;
r[0] = R;
for (int j = 0; j < m; j++){
int t = i >> j & 1;
l[j + 1] = (l[j] - t + 1) / 2;
r[j + 1] = (r[j] + 1) / 2;
}
vector<long long> dp(m + 1, 0);
for (int j = 0; j <= m; j++){
if (l[j] == r[j]){
dp[j] = pre[j][i & ((1 << j) - 1)];
for (int k = 0; k < j; k++){
dp[j] -= dp[k] * pre[j - k][(i >> k) & ((1 << (j - k)) - 1)] % MOD;
if (dp[j] < 0){
dp[j] += MOD;
}
}
ans[i] += dp[j] * pre[m - j + 1][i >> j] % MOD;
}
}
ans[i] %= MOD;
}
}
for (int i = 1; i <= X; i++){
cout << ans[i];
if (i < X){
cout << ' ';
}
}
cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 3860kb
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: 293ms
memory: 175184kb
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