File tree Expand file tree Collapse file tree
tests/library_checker_aizu_tests/convolution Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments