File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -52,17 +52,20 @@ namespace cp_algo::linalg {
5252 }
5353 // Find transform matrices while we're at it...
5454 if constexpr (mode == full) {
55- for (size_t i = 0 ; i < size (basis) ; i++) {
56- for (size_t j = i + 1 ; j < size (basis) ; j++) {
55+ for (size_t i = 0 ; i < n ; i++) {
56+ for (size_t j = i + 1 ; j < n ; j++) {
5757 basis[i].reduce_by (basis[j]);
5858 }
5959 basis[i].normalize ();
60- basis[i] = vec<base>(
61- basis[i][std::slice (n, n, 1 )]
62- ) * (base (1 ) / basis[i][i]);
6360 }
6461 auto T = matrix::from_range (basis_init);
6562 auto Tinv = matrix::from_range (basis);
63+ std::ignore = Tinv.sort_classify (n);
64+ for (size_t i = 0 ; i < n; i++) {
65+ Tinv[i] = vec<base>(
66+ Tinv[i][std::slice (n, n, 1 )]
67+ ) * (base (1 ) / Tinv[i][i]);
68+ }
6669 return std::tuple{T, Tinv, charps};
6770 } else {
6871 return charps;
Original file line number Diff line number Diff line change @@ -28,9 +28,11 @@ namespace cp_algo::linalg {
2828
2929 matrix& operator *=(base t) {for (auto &it: *this ) it *= t; return *this ;}
3030 matrix operator *(base t) const {return matrix (*this ) *= t;}
31+ matrix& operator /=(base t) {return *this *= base (1 ) / t;}
32+ matrix operator /(base t) const {return matrix (*this ) /= t;}
3133
3234 // Make sure the result is matrix, not Base
33- matrix& operator *=(matrix const & t) {return *this = *this * t;}
35+ matrix& operator *=(matrix const & t) {return *this = *this * t;}
3436
3537 void read () {
3638 for (auto &it: *this ) {
@@ -227,7 +229,7 @@ namespace cp_algo::linalg {
227229 };
228230 }
229231 }
230- private:
232+
231233 // To be called after a gaussian elimination run
232234 // Sorts rows by pivots and classifies
233235 // variables into pivots and free
Original file line number Diff line number Diff line change 11// @brief Pow of Matrix (Frobenius)
22#define PROBLEM " https://judge.yosupo.jp/problem/pow_of_matrix"
33#pragma GCC optimize("Ofast,unroll-loops")
4- #pragma GCC target("tune=native")
5- #define CP_ALGO_MAXN 1 << 10
4+ #define CP_ALGO_MAXN 256
65#include " cp-algo/linalg/frobenius.hpp"
76#include < bits/stdc++.h>
87
You can’t perform that action at this time.
0 commit comments