@@ -4,31 +4,37 @@ template <class mint>
44struct FormalPowerSeries : vector<mint> {
55 using vector<mint>::vector;
66 using FPS = FormalPowerSeries;
7- FPS &operator +=(const FPS &r) {
7+ FormalPowerSeries (const vector<mint>& r) : vector<mint>(r) {}
8+ FormalPowerSeries (vector<mint>&& r) : vector<mint>(std::move(r)) {}
9+ FPS& operator =(const vector<mint>& r) {
10+ vector<mint>::operator =(r);
11+ return *this ;
12+ }
13+ FPS& operator +=(const FPS& r) {
814 if (r.size () > this ->size ()) this ->resize (r.size ());
915 for (int i = 0 ; i < (int )r.size (); i++) (*this )[i] += r[i];
1016 return *this ;
1117 }
12- FPS & operator +=(const mint & r) {
18+ FPS& operator +=(const mint& r) {
1319 if (this ->empty ()) this ->resize (1 );
1420 (*this )[0 ] += r;
1521 return *this ;
1622 }
17- FPS & operator -=(const FPS & r) {
23+ FPS& operator -=(const FPS& r) {
1824 if (r.size () > this ->size ()) this ->resize (r.size ());
1925 for (int i = 0 ; i < (int )r.size (); i++) (*this )[i] -= r[i];
2026 return *this ;
2127 }
22- FPS & operator -=(const mint & r) {
28+ FPS& operator -=(const mint& r) {
2329 if (this ->empty ()) this ->resize (1 );
2430 (*this )[0 ] -= r;
2531 return *this ;
2632 }
27- FPS & operator *=(const mint & v) {
33+ FPS& operator *=(const mint& v) {
2834 for (int k = 0 ; k < (int )this ->size (); k++) (*this )[k] *= v;
2935 return *this ;
3036 }
31- FPS & operator /=(const FPS & r) {
37+ FPS& operator /=(const FPS& r) {
3238 if (this ->size () < r.size ()) {
3339 this ->clear ();
3440 return *this ;
@@ -38,7 +44,7 @@ struct FormalPowerSeries : vector<mint> {
3844 FPS f (*this ), g (r);
3945 g.shrink ();
4046 mint coeff = g.at (g.size () - 1 ).inv ();
41- for (auto & x : g) x *= coeff;
47+ for (auto & x : g) x *= coeff;
4248 int deg = (int )f.size () - (int )g.size () + 1 ;
4349 int gs = g.size ();
4450 FPS quo (deg);
@@ -52,19 +58,19 @@ struct FormalPowerSeries : vector<mint> {
5258 }
5359 return *this = ((*this ).rev ().pre (n) * r.rev ().inv (n)).pre (n).rev ();
5460 }
55- FPS & operator %=(const FPS & r) {
61+ FPS& operator %=(const FPS& r) {
5662 *this -= *this / r * r;
5763 shrink ();
5864 return *this ;
5965 }
60- FPS operator +(const FPS & r) const { return FPS (*this ) += r; }
61- FPS operator +(const mint & v) const { return FPS (*this ) += v; }
62- FPS operator -(const FPS & r) const { return FPS (*this ) -= r; }
63- FPS operator -(const mint & v) const { return FPS (*this ) -= v; }
64- FPS operator *(const FPS & r) const { return FPS (*this ) *= r; }
65- FPS operator *(const mint & v) const { return FPS (*this ) *= v; }
66- FPS operator /(const FPS & r) const { return FPS (*this ) /= r; }
67- FPS operator %(const FPS & r) const { return FPS (*this ) %= r; }
66+ FPS operator +(const FPS& r) const { return FPS (*this ) += r; }
67+ FPS operator +(const mint& v) const { return FPS (*this ) += v; }
68+ FPS operator -(const FPS& r) const { return FPS (*this ) -= r; }
69+ FPS operator -(const mint& v) const { return FPS (*this ) -= v; }
70+ FPS operator *(const FPS& r) const { return FPS (*this ) *= r; }
71+ FPS operator *(const mint& v) const { return FPS (*this ) *= v; }
72+ FPS operator /(const FPS& r) const { return FPS (*this ) /= r; }
73+ FPS operator %(const FPS& r) const { return FPS (*this ) %= r; }
6874 FPS operator -() const {
6975 FPS ret (this ->size ());
7076 for (int i = 0 ; i < (int )this ->size (); i++) ret[i] = -(*this )[i];
@@ -130,7 +136,7 @@ struct FormalPowerSeries : vector<mint> {
130136 }
131137 mint eval (mint x) const {
132138 mint r = 0 , w = 1 ;
133- for (auto & v : *this ) r += w * v, w *= x;
139+ for (auto & v : *this ) r += w * v, w *= x;
134140 return r;
135141 }
136142 FPS log (int deg = -1 ) const {
@@ -160,10 +166,10 @@ struct FormalPowerSeries : vector<mint> {
160166 return FPS (deg, mint (0 ));
161167 }
162168
163- static void * ntt_ptr;
169+ static void * ntt_ptr;
164170 static void set_ntt ();
165- FPS & operator *=(const FPS & r);
166- FPS middle_product (const FPS & r) const ;
171+ FPS& operator *=(const FPS& r);
172+ FPS middle_product (const FPS& r) const ;
167173 void ntt ();
168174 void intt ();
169175 void ntt_doubling ();
@@ -172,4 +178,4 @@ struct FormalPowerSeries : vector<mint> {
172178 FPS exp (int deg = -1 ) const ;
173179};
174180template <typename mint>
175- void * FormalPowerSeries<mint>::ntt_ptr = nullptr ;
181+ void * FormalPowerSeries<mint>::ntt_ptr = nullptr ;
0 commit comments