QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#465188#8834. Formal Fringucup-team1198#AC ✓161ms7772kbC++201.6kb2024-07-06 18:20:132024-07-06 18:20:14

Judging History

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

  • [2024-07-06 18:20:14]
  • 评测
  • 测评结果:AC
  • 用时:161ms
  • 内存:7772kb
  • [2024-07-06 18:20:13]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int MOD = 998244353;

int add(int a, int b) {
  if (a + b < MOD)
    return a + b;
  return a + b - MOD;
}

int sub(int a, int b) {
  if (a >= b)
    return a - b;
  return a + MOD - b;
}

int mul(int a, int b) {
  return a * 1ll * b % MOD;
}

int pw(int a, int n) {
  int ans = 1;
  while (n) {
    if (n & 1)
      ans = mul(ans, a);
    n >>= 1;
    a = mul(a, a);
  }
  return ans;
}

const int MAXN = 1e6 + 100;
int dp[MAXN], f[30];


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1];
    if (i % 2 == 0) {
      dp[i] = add(dp[i], dp[i / 2]);
    }
  }
  for (int l = 1; (1 << l) <= n + 1; ++l) {
    f[l] = dp[(1 << l) - 1];
    for (int l1 = 1; l1 < l; ++l1) {
      f[l] = sub(f[l], mul(f[l1], dp[(1 << (l - l1)) - 1]));
    }
  }

  for (int x = 1; x <= n; ++x) {
    int x1 = x;
    vector<int> bits;
    while (x1) {
      bits.push_back(x1 % 2);
      x1 /= 2;
    }
    int ans = 0;
    x1 = x;
    for (int i = (int)bits.size() - 1; i >= 0 && bits[i] == 1; --i) {
      x1 ^= (1 << i);
      ans = add(ans, mul(dp[x1], f[bits.size() - i]));
    }
    cout << ans << " ";
  }
  cout << "\n";

  
  return 0;
}

详细

Test #1:

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

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: 3628kb

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: 161ms
memory: 7772kb

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