1515namespace cp_algo ::math {
1616 template <typename T, class Alloc = big_alloc<T>>
1717 struct poly_t {
18+ using Vector = std::vector<T, Alloc>;
1819 using base = T;
19- std::vector<T, Alloc> a;
20+ Vector a;
2021
2122 poly_t & normalize () {
2223 while (deg () >= 0 && lead () == base (0 )) {
@@ -27,8 +28,8 @@ namespace cp_algo::math {
2728
2829 poly_t (){}
2930 poly_t (T a0): a{a0} {normalize ();}
30- poly_t (auto const & t): a(t.begin(), t.end() ) {normalize ();}
31- poly_t (std::vector<T, Alloc> &&t): a(std::move(t)) {normalize ();}
31+ poly_t (Vector const & t): a(t) {normalize ();}
32+ poly_t (Vector &&t): a(std::move(t)) {normalize ();}
3233
3334 poly_t & negate_inplace () {
3435 std::ranges::transform (a, begin (a), std::negate{});
@@ -204,7 +205,7 @@ namespace cp_algo::math {
204205 return *this ;
205206 }
206207 poly_t integr () const { // calculate integral with C = 0
207- std::vector<T> res (deg () + 2 );
208+ Vector res (deg () + 2 );
208209 for (int i = 0 ; i <= deg (); i++) {
209210 res[i + 1 ] = a[i] * small_inv<T>(i + 1 );
210211 }
@@ -306,7 +307,7 @@ namespace cp_algo::math {
306307 return poly_t (T (0 ));
307308 }
308309 assert ((*this )[0 ] != T (0 ));
309- std::vector<T> Q (n);
310+ Vector Q (n);
310311 Q[0 ] = bpow (a[0 ], k);
311312 auto a0inv = a[0 ].inv ();
312313 for (int i = 1 ; i < (int )n; i++) {
@@ -389,10 +390,10 @@ namespace cp_algo::math {
389390 // requires multiplying polynomials of size deg() and n+deg()!
390391 poly_t chirpz (T z, int n) const { // P(1), P(z), P(z^2), ..., P(z^(n-1))
391392 if (is_zero ()) {
392- return std::vector<T> (n, 0 );
393+ return Vector (n, 0 );
393394 }
394395 if (z == T (0 )) {
395- std::vector<T> ans (n, (*this )[0 ]);
396+ Vector ans (n, (*this )[0 ]);
396397 if (n > 0 ) {
397398 ans[0 ] = accumulate (begin (a), end (a), T (0 ));
398399 }
@@ -405,7 +406,7 @@ namespace cp_algo::math {
405406
406407 // res[i] = prod_{1 <= j <= i} 1/(1 - z^j)
407408 static auto _1mzk_prod_inv (T z, int n) {
408- std::vector<T> res (n, 1 ), zk (n);
409+ Vector res (n, 1 ), zk (n);
409410 zk[0 ] = 1 ;
410411 for (int i = 1 ; i < n; i++) {
411412 zk[i] = zk[i - 1 ] * z;
@@ -421,12 +422,12 @@ namespace cp_algo::math {
421422 // prod_{0 <= j < n} (1 - z^j x)
422423 static auto _1mzkx_prod (T z, int n) {
423424 if (n == 1 ) {
424- return poly_t (std::vector<T> {1 , -1 });
425+ return poly_t (Vector {1 , -1 });
425426 } else {
426427 auto t = _1mzkx_prod (z, n / 2 );
427428 t *= t.mulx (bpow (z, n / 2 ));
428429 if (n % 2 ) {
429- t *= poly_t (std::vector<T> {1 , -bpow (z, n - 1 )});
430+ t *= poly_t (Vector {1 , -bpow (z, n - 1 )});
430431 }
431432 return t;
432433 }
@@ -443,7 +444,7 @@ namespace cp_algo::math {
443444 return std::vector{(*this )[1 ], (*this )[0 ] - (*this )[1 ]};
444445 }
445446 }
446- std::vector<T> y (n);
447+ Vector y (n);
447448 for (int i = 0 ; i < n; i++) {
448449 y[i] = (*this )[i];
449450 }
@@ -465,7 +466,7 @@ namespace cp_algo::math {
465466
466467 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)
467468 if (R - L == 1 ) {
468- return res[v] = std::vector<T> {-*L, 1 };
469+ return res[v] = Vector {-*L, 1 };
469470 } else {
470471 auto M = L + (R - L) / 2 ;
471472 return res[v] = build (res, 2 * v, L, M) * build (res, 2 * v + 1 , M, R);
@@ -483,7 +484,7 @@ namespace cp_algo::math {
483484 }
484485 }
485486
486- poly_t to_newton (std::vector<T> p) {
487+ poly_t to_newton (Vector p) {
487488 if (is_zero ()) {
488489 return *this ;
489490 }
@@ -493,7 +494,7 @@ namespace cp_algo::math {
493494 return to_newton (tree, 1 , begin (p), end (p));
494495 }
495496
496- std::vector<T> eval (std::vector<poly_t > &tree, int v, auto l, auto r) { // auxiliary evaluation function
497+ Vector eval (std::vector<poly_t > &tree, int v, auto l, auto r) { // auxiliary evaluation function
497498 if (r - l == 1 ) {
498499 return {eval (*l)};
499500 } else {
@@ -505,10 +506,10 @@ namespace cp_algo::math {
505506 }
506507 }
507508
508- std::vector<T> eval (std::vector<T> x) { // evaluate polynomial in (x1, ..., xn)
509+ Vector eval (Vector x) { // evaluate polynomial in (x1, ..., xn)
509510 size_t n = x.size ();
510511 if (is_zero ()) {
511- return std::vector<T> (n, T (0 ));
512+ return Vector (n, T (0 ));
512513 }
513514 std::vector<poly_t > tree (4 * n);
514515 build (tree, 1 , begin (x), end (x));
@@ -526,7 +527,7 @@ namespace cp_algo::math {
526527 }
527528 }
528529
529- static auto inter (std::vector<T> x, std::vector<T> y) { // interpolates minimum polynomial from (xi, yi) pairs
530+ static auto inter (Vector x, Vector y) { // interpolates minimum polynomial from (xi, yi) pairs
530531 size_t n = x.size ();
531532 std::vector<poly_t > tree (4 * n);
532533 return build (tree, 1 , begin (x), end (x)).deriv ().inter (tree, 1 , begin (y), end (y));
@@ -552,15 +553,15 @@ namespace cp_algo::math {
552553 }
553554
554555 static poly_t ones (size_t n) { // P(x) = 1 + x + ... + x^{n-1}
555- return std::vector<T> (n, 1 );
556+ return Vector (n, 1 );
556557 }
557558
558559 static poly_t expx (size_t n) { // P(x) = e^x (mod x^n)
559560 return ones (n).borel ();
560561 }
561562
562563 static poly_t log1px (size_t n) { // P(x) = log(1+x) (mod x^n)
563- std::vector<T> coeffs (n, 0 );
564+ Vector coeffs (n, 0 );
564565 for (size_t i = 1 ; i < n; i++) {
565566 coeffs[i] = (i & 1 ? T (i).inv () : -T (i).inv ());
566567 }
@@ -602,7 +603,7 @@ namespace cp_algo::math {
602603 }
603604
604605 poly_t x2 () { // P(x) -> P(x^2)
605- std::vector<T> res (2 * a.size ());
606+ Vector res (2 * a.size ());
606607 for (size_t i = 0 ; i < a.size (); i++) {
607608 res[2 * i] = a[i];
608609 }
@@ -612,7 +613,7 @@ namespace cp_algo::math {
612613 // Return {P0, P1}, where P(x) = P0(x) + xP1(x)
613614 std::array<poly_t , 2 > bisect (size_t n) const {
614615 n = std::min (n, size (a));
615- std::vector<T> res[2 ];
616+ Vector res[2 ];
616617 for (size_t i = 0 ; i < n; i++) {
617618 res[i % 2 ].push_back (a[i]);
618619 }
0 commit comments