-
Notifications
You must be signed in to change notification settings - Fork 0
/
fwt.cpp
29 lines (29 loc) · 986 Bytes
/
fwt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void FWT_or(int *a, int opt)
{
for (int i = 1; i < N; i <<= 1)
for (int p = i << 1, j = 0; j < N; j += p)
for (int k = 0; k < i; ++k)
if (opt == 1)a[i + j + k] = (a[j + k] + a[i + j + k]) % MOD;
else a[i + j + k] = (a[i + j + k] + MOD - a[j + k]) % MOD;
}
void FWT_and(int *a, int opt)
{
for (int i = 1; i < N; i <<= 1)
for (int p = i << 1, j = 0; j < N; j += p)
for (int k = 0; k < i; ++k)
if (opt == 1)a[j + k] = (a[j + k] + a[i + j + k]) % MOD;
else a[j + k] = (a[j + k] + MOD - a[i + j + k]) % MOD;
}
void FWT_xor(int *a, int opt)
{
for (int i = 1; i < N; i <<= 1)
for (int p = i << 1, j = 0; j < N; j += p)
for (int k = 0; k < i; ++k)
{
int X = a[j + k], Y = a[i + j + k];
a[j + k] = (X + Y) % MOD; a[i + j + k] = (X + MOD - Y) % MOD;
if (opt == -1)a[j + k] = 1ll * a[j + k] * inv2 % MOD, a[i + j + k] = 1ll * a[i + j + k] * inv2 % MOD;
}
}
//下标从0开始 1 正 -1 逆
//3 3 7 7 7 7 7 2 2 2 2 2 2 10 11 13== 3 3 3 3 3 ==15 15