Skip to content

Commit 1a3e7ad

Browse files
committed
fix
1 parent ca0ad54 commit 1a3e7ad

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

cp-algo/math/fft.hpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace cp_algo::math::fft {
8484
}
8585
}
8686

87-
auto operator *= (dft const& B) {
87+
std::vector<base> operator *= (dft const& B) {
8888
assert(A.size() == B.A.size());
8989
size_t n = A.size();
9090
if(!n) {
@@ -95,12 +95,14 @@ namespace cp_algo::math::fft {
9595
}
9696
fft(A, n);
9797
reverse(begin(A) + 1, end(A));
98-
std::vector<base> res(n);
9998
for(size_t i = 0; i < n; i++) {
100-
res[i] = A[i];
101-
res[i] /= n;
99+
A[i] /= n;
100+
}
101+
if constexpr (std::is_same_v<base, point>) {
102+
return A;
103+
} else {
104+
return {begin(A), end(A)};
102105
}
103-
return res;
104106
}
105107

106108
auto operator * (dft const& B) const {
@@ -125,16 +127,22 @@ namespace cp_algo::math::fft {
125127
}
126128
}
127129

128-
auto operator *= (dft const& B) {
130+
std::vector<base> operator *= (dft const& B) {
129131
assert(A.size() == B.A.size());
130132
size_t n = A.size();
131133
if(!n) {
132134
return std::vector<base>();
133135
}
134136
std::vector<point> C(n);
135-
for(size_t i = 0; i < n; i++) {
136-
C[i] = A[i] * (B[i] + conj(B[(n - i) % n]));
137-
A[i] = A[i] * (B[i] - conj(B[(n - i) % n]));
137+
for(size_t i = 0; 2 * i <= n; i++) {
138+
int x = i;
139+
int y = (n - i) % n;
140+
std::tie(C[x], A[x], C[y], A[y]) = std::make_tuple(
141+
A[x] * (B[x] + conj(B[y])),
142+
A[x] * (B[x] - conj(B[y])),
143+
A[y] * (B[y] + conj(B[x])),
144+
A[y] * (B[y] - conj(B[x]))
145+
);
138146
}
139147
fft(C, n);
140148
fft(A, n);

verify/poly/wildcard.test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define PROBLEM "https://judge.yosupo.jp/problem/wildcard_pattern_matching"
33
#pragma GCC optimize("Ofast,unroll-loops")
44
#pragma GCC target("avx2,tune=native")
5+
#define CP_ALGO_MAXN 1 << 19
56
#include "cp-algo/math/poly.hpp"
67
#include <bits/stdc++.h>
78

0 commit comments

Comments
 (0)