Skip to content

Commit 0d77258

Browse files
committed
Update
1 parent 72c8196 commit 0d77258

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

.verify-helper/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[[languages.cpp.environments]]
22
CXX = "g++"
3-
CXXFLAGS = ["-std=c++20", "-Wall", "-Wextra", "-O2", "-march=native", "-mavx2"]
3+
CXXFLAGS = ["-std=c++20", "-Wall", "-Wextra", "-O2", "-march=native"]

cp-algo/math/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace cp_algo::math {
88
#else
99
const int maxn = 1 << 19;
1010
#endif
11-
const int magic = 128; // threshold for sizes to run the naive algo
11+
const int magic = 64; // threshold for sizes to run the naive algo
1212

1313
auto bpow(auto const& x, int64_t n, auto const& one, auto op) {
1414
if(n == 0) {

cp-algo/math/fft.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,15 @@ namespace cp_algo::math::fft {
216216

217217
template<modint_type base>
218218
struct dft<base> {
219-
static constexpr int split = 1 << 15;
219+
int split;
220220
cvector A, B;
221221

222222
dft(std::vector<base> const& a, size_t n): A(n), B(n) {
223+
split = std::sqrt(base::mod());
223224
cvector::exec_on_roots(2 * n, size(a), [&](size_t i, point rt) {
224-
A.set(i % n, A.get(i % n) + ftype(a[i].rem() % split) * rt);
225-
B.set(i % n, B.get(i % n) + ftype(a[i].rem() / split) * rt);
225+
size_t ti = std::min(i, i - n);
226+
A.set(ti, A.get(ti) + ftype(a[i].rem() % split) * rt);
227+
B.set(ti, B.get(ti) + ftype(a[i].rem() / split) * rt);
226228

227229
});
228230
if(n) {
@@ -248,19 +250,20 @@ namespace cp_algo::math::fft {
248250
B.ifft();
249251
C.ifft();
250252
res.resize(2 * n);
253+
auto splitsplit = (base(split) * split).rem();
251254
cvector::exec_on_roots(2 * n, n, [&](size_t i, point rt) {
252255
rt = conj(rt);
253256
auto Ai = A.get(i) * rt;
254257
auto Bi = B.get(i) * rt;
255258
auto Ci = C.get(i) * rt;
256-
base A0 = llround(real(Ai));
257-
base A1 = llround(real(Ci));
258-
base A2 = llround(real(Bi));
259-
res[i] = A0 + A1 * split + A2 * split * split;
260-
base B0 = llround(imag(Ai));
261-
base B1 = llround(imag(Ci));
262-
base B2 = llround(imag(Bi));
263-
res[n + i] = B0 + B1 * split + B2 * split * split;
259+
int64_t A0 = llround(real(Ai));
260+
int64_t A1 = llround(real(Ci));
261+
int64_t A2 = llround(real(Bi));
262+
res[i] = A0 + A1 * split + A2 * splitsplit;
263+
int64_t B0 = llround(imag(Ai));
264+
int64_t B1 = llround(imag(Ci));
265+
int64_t B2 = llround(imag(Bi));
266+
res[n + i] = B0 + B1 * split + B2 * splitsplit;
264267
});
265268
}
266269
void mul(auto &&B, auto& res) {

0 commit comments

Comments
 (0)