Skip to content

Commit 7e06c5f

Browse files
committed
first draft of xor conv
1 parent ec7f5bb commit 7e06c5f

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include "../math/mod_division.hpp"
3+
void fwht(int n, vi& a) {
4+
for (int i = 1; i != n; i <<= 1)
5+
for (int j = 0; j != n; j += i << 1)
6+
for (int k = 0; k != i; k++) {
7+
int x = a[j + k], y = a[i + j + k];
8+
a[j + k] = (x + y) % mod;
9+
a[i + j + k] = (x - y + mod) % mod;
10+
}
11+
}
12+
vi xor_conv(vi& a, vi& b) {
13+
int n = sz(a), inv = mod_div(1, n);
14+
fwht(n, a);
15+
fwht(n, b);
16+
vi res(n);
17+
rep(i, 0, n) res[i] = 1LL * a[i] * b[i] % mod;
18+
fwht(n, res);
19+
rep(i, 0, n) res[i] = 1LL * res[i] * inv % mod;
20+
return res;
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#define PROBLEM \
2+
"https://judge.yosupo.jp/problem/bitwise_xor_convolution"
3+
#include "../template.hpp"
4+
#include "../../../library/convolution/xor_convolution.hpp"
5+
istream& operator>>(istream& is, vector<int>& v) {
6+
for (int i = 0; i < sz(v); i++) is >> v[i];
7+
return is;
8+
}
9+
int main() {
10+
cin.tie(0)->sync_with_stdio(0);
11+
int n;
12+
cin >> n;
13+
vi a(1 << n), b(1 << n);
14+
cin >> a >> b;
15+
vi c = xor_conv(a, b);
16+
for (int i = 0; i < (1 << n); i++) cout << c[i] << ' ';
17+
cout << '\n';
18+
return 0;
19+
}

0 commit comments

Comments
 (0)