We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5dd22f5 commit 05e100dCopy full SHA for 05e100d
library/convolution/xor_convolution.hpp
@@ -1,9 +1,16 @@
1
#pragma once
2
#include "../math/mod_division.hpp"
3
+//! https://codeforces.com/blog/entry/127823
4
+//! @code
5
+//! vi c = xor_conv(a, b);
6
+//! // must have sz(a) == sz(b) == a power of 2
7
+//! // c[k] = sum of a[i]*b[j] where i^j==k
8
+//! @endcode
9
+//! @time O(n log n)
10
+//! @space O(n)
11
void fwht(int n, vi& a) {
- for (int i = 1; i != n; i <<= 1)
- for (int j = 0; j != n; j += i << 1)
- for (int k = 0; k != i; k++) {
12
+ for (int i = 1; i < n; i *= 2)
13
+ for (int j = 0; j < n; j += 2 * i) rep(k, 0, i) {
14
int x = a[j + k], y = a[i + j + k];
15
a[j + k] = (x + y) % mod;
16
a[i + j + k] = (x - y + mod) % mod;
0 commit comments