QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#769155#8834. Formal FringhbbbbAC ✓506ms19376kbC++231.4kb2024-11-21 16:22:122024-11-21 16:22:14

Judging History

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

  • [2024-11-21 16:22:14]
  • 评测
  • 测评结果:AC
  • 用时:506ms
  • 内存:19376kb
  • [2024-11-21 16:22:12]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <array>
#include <queue>
#include <set>
#include <map>
using namespace std;

using ll = long long;

constexpr ll MOD = 998244353ll;

constexpr int N = 1e6 + 5;

array<ll, N> f, g;
int n;

inline int highbit(int x)
{
	if (x == 0) return -1;
	return (int)log2(x);
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	f[0] = 1ll;
	for (int i = 0; i < 20; i++)
	{
		for (int j = (1 << i); j < N; j++)
		{
			f[j] = (f[j] + f[j - (1 << i)]);
			(f[j] >= MOD ? f[j] -= MOD : 0);
		}
	}
	g[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int k = 0; k < 20; k++)
		{
			if (i % (1 << k) || i < (1 << (k + 1))) continue;
			g[i] = (g[i] + f[1 << k] * g[(i - (1 << (k + 1))) >> k] % MOD);
			g[i] >= MOD ? g[i] -= MOD : 0;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		ll ans = 0ll;
		for (int k = 0; k < 20; k++)
		{
			if ((1 << k) > i) break;
			int x = (1 << k) - (i % (1 << k));
			if (i < ((1 << k) + (1 << k) - x) || highbit((i + x) >> 1) == highbit((i - x) >> 1)) continue;
			//cout << "!!: " << i << " " << k << " " << x << "\n";
			int ns = i - (1 << k) - ((1 << k) - x);
			if (ns % (1 << k)) continue;
			ll val = f[(1 << k) - x] * g[ns >> k] % MOD;
			ans = (ans + val);
			ans >= MOD ? ans -= MOD : 0;
		}
		cout << ans << " ";
	}
	cout << "\n";
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 13ms
memory: 11644kb

input:

10

output:

1 1 2 1 1 3 6 1 1 2 

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 16ms
memory: 13296kb

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: 506ms
memory: 19376kb

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