@@ -26,7 +26,7 @@ namespace cp_algo::math {
26
26
poly_t (std::vector<T> const & t): a(t) {normalize ();}
27
27
poly_t (std::vector<T>&& t): a(std::move(t)) {normalize ();}
28
28
29
- poly_t operator -() const {return poly::impl::neg ( *this );}
29
+ poly_t operator -() const {return poly::impl::neg_inplace ( poly_t ( *this ) );}
30
30
poly_t & operator += (poly_t const & t) {return poly::impl::add (*this , t);}
31
31
poly_t & operator -= (poly_t const & t) {return poly::impl::sub (*this , t);}
32
32
poly_t operator + (poly_t const & t) const {return poly_t (*this ) += t;}
@@ -69,8 +69,10 @@ namespace cp_algo::math {
69
69
poly_t operator * (T const & x) const {return poly_t (*this ) *= x;}
70
70
poly_t operator / (T const & x) const {return poly_t (*this ) /= x;}
71
71
72
- poly_t reverse (size_t n) const {return poly::impl::reverse (*this , n);}
73
- poly_t reverse () const {return reverse (size (a));}
72
+ poly_t & reverse (size_t n) {return poly::impl::reverse (*this , n);}
73
+ poly_t & reverse () {return reverse (size (a));}
74
+ poly_t reversed (size_t n) {return poly_t (*this ).reverse (n);}
75
+ poly_t reversed () {return poly_t (*this ).reverse ();}
74
76
75
77
std::array<poly_t , 2 > divmod (poly_t const & b) const {
76
78
return poly::impl::divmod (*this , b);
@@ -433,7 +435,7 @@ namespace cp_algo::math {
433
435
poly_t p_over_q = poly_t (y).chirpz (z, n);
434
436
poly_t q = _1mzkx_prod (z, n);
435
437
436
- return (p_over_q * q).mod_xk (n).reverse (n);
438
+ return (p_over_q * q).mod_xk_inplace (n).reverse (n);
437
439
}
438
440
439
441
static poly_t build (std::vector<poly_t > &res, int v, auto L, auto R) { // builds evaluation tree for (x-a1)(x-a2)...(x-an)
@@ -546,7 +548,7 @@ namespace cp_algo::math {
546
548
547
549
// [x^k] (a corr b) = sum_{i} a{(k-m)+i}*bi
548
550
static poly_t corr (poly_t const & a, poly_t const & b) { // cross-correlation
549
- return a * b.reverse ();
551
+ return a * b.reversed ();
550
552
}
551
553
552
554
// [x^k] (a semicorr b) = sum_i a{i+k} * b{i}
@@ -609,11 +611,11 @@ namespace cp_algo::math {
609
611
auto P0f = fft::dft<T>(P0.a , N);
610
612
auto P1f = fft::dft<T>(P1.a , N);
611
613
612
- Q = poly_t (Q0f * Q0f) - poly_t (Q1f * Q1f).mul_xk (1 );
614
+ Q = poly_t (Q0f * Q0f) -= poly_t (Q1f * Q1f).mul_xk_inplace (1 );
613
615
if (k % 2 ) {
614
- P = poly_t (Q0f *= P1f) - poly_t (Q1f *= P0f);
616
+ P = poly_t (Q0f *= P1f) -= poly_t (Q1f *= P0f);
615
617
} else {
616
- P = poly_t (Q0f *= P0f) - poly_t (Q1f *= P1f).mul_xk (1 );
618
+ P = poly_t (Q0f *= P0f) -= poly_t (Q1f *= P1f).mul_xk_inplace (1 );
617
619
}
618
620
k /= 2 ;
619
621
}
0 commit comments