QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#543641 | #8834. Formal Fring | ucup-team1069# | AC ✓ | 117ms | 9680kb | C++20 | 1.6kb | 2024-09-01 17:43:52 | 2024-09-01 17:43:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size();
#define all(x) x.begin(), x.end();
const int N = 1e6 + 200;
const int mod = 998244353;
int n, f[N], dp[N];
void solve() {
cin >> n;
f[0] = 1;
f[1] = 1;
for (int i = 2; i <= n; ++i) {
f[i] = f[i - 1];
if (i % 2 == 0) {
f[i] += f[i / 2];
f[i] %= mod;
}
}
dp[1] = 1;
dp[3] = 1;
for (int i = 7; i <= n; i = i * 2 + 1) {
dp[i] = f[i];
for (int j = 1; j < i; j = j * 2 + 1) {
int k = i - j;
while (k % 2 == 0) k /= 2;
dp[i] = (dp[i] - (f[j] * 1ll * dp[k] % mod) + mod) % mod;
}
}
for (int i = 1; i <= n; ++i) {
/* if (i != 2) continue; */
int l = 0;
int j = i, p = 1;
while (true) {
if (__builtin_popcount(j + 1) == 1) {
break;
}
if (j & 1) {
l += p;
}
j /= 2;
p *= 2;
}
int r = i - l;
while (r % 2 == 0) r /= 2;
if (r == i) {
cout << f[r] << " ";
continue;
}
int cnt = 0;
int pw = -1;
while (r >= 1) {
cnt += dp[r] * 1ll * f[l] % mod;
cnt %= mod;
/* cout << l << " " << r << '\n'; */
r /= 2;
l += p;
pw = p;
p *= 2;
}
cout << cnt << " ";
}
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T = 1;
/* cin >> T; */
while (T--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5820kb
input:
10
output:
1 1 2 1 1 3 6 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 5876kb
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: 117ms
memory: 9680kb
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