CF1906K 题解
EuphoricStar · · 题解
UNR #2 黎明前的巧克力。
枚举两个人选的卡的并集
考虑将
令
考虑
令
总时间复杂度
// Problem: K. Deck-Building Game
// Contest: Codeforces - 2023-2024 ICPC, Asia Jakarta Regional Contest (Online Mirror, Unrated, ICPC Rules, Teams Preferred)
// URL: https://codeforces.com/problemset/problem/1906/K
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 131100;
const int N = 131072;
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, a[maxn];
inline void FWT(ll *a, ll o) {
for (int k = 1; k < N; k <<= 1) {
for (int i = 0; i < N; 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) * o % mod;
a[i + j + k] = (x - y + mod) * o % mod;
}
}
}
}
void solve() {
scanf("%lld", &n);
for (int i = 0, x; i < n; ++i) {
scanf("%d", &x);
a[x] += 2;
}
a[0] += n;
FWT(a, 1);
ll inv4 = qpow(4, mod - 2);
for (int i = 0; i < N; ++i) {
ll x = (n * 3 - a[i] + mod) * inv4 % mod;
a[i] = ((x & 1) ? mod - 1 : 1) * qpow(3, n - x) % mod;
}
FWT(a, inv2);
printf("%lld\n", a[0]);
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}