AtCoder Beginner Contest 212 H Nim Counting
牛逼题……
考虑如果定义 \(x^a \times x^b = x^{a \oplus b}\),设 \(f(x) = \sum\limits_{i=1}^k x^{a_i}\),那么题目就是求,\(\forall w > 0, \sum\limits_{i=1}^n (f(x))^i\),指数为 \(w\) 的系数之和。
考虑 FWT,把每一项变成 \(\sum\limits_{i=1}^n x_i\) 再逆回去。
code
// Problem: H - Nim Counting
// Contest: AtCoder - AtCoder Beginner Contest 212
// URL: https://atcoder.jp/contests/abc212/tasks/abc212_h
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 200100;
const int U = (1 << 16);
const ll mod = 998244353;
const ll inv2 = (mod + 1) / 2;
inline ll qpow(ll b, ll p) {
ll res = 1;
while (p) {
if (p & 1) {
res = res * b % mod;
}
b = b * b % mod;
p >>= 1;
}
return res;
}
ll n, m, a[maxn], b[maxn];
void FWT(ll *a, ll op) {
for (int k = 1; k < U; k <<= 1) {
for (int i = 0; i < U; i += (k << 1)) {
for (int j = 0; j < k; ++j) {
ll x = a[i + j], y = a[i + j + k];
a[i + j] = (x + y) * op % mod;
a[i + j + k] = (x - y + mod) % mod * op % mod;
}
}
}
}
void solve() {
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= m; ++i) {
scanf("%lld", &a[i]);
++b[a[i]];
}
FWT(b, 1);
for (int i = 0; i < U; ++i) {
if (b[i] == 1) {
b[i] = n;
continue;
}
b[i] = ((qpow(b[i], n + 1) + mod - 1) % mod * qpow((b[i] + mod - 1) % mod, mod - 2) % mod + mod - 1) % mod;
}
FWT(b, inv2);
ll ans = 0;
for (int i = 1; i < U; ++i) {
ans = (ans + b[i]) % mod;
}
printf("%lld\n", ans);
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}