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 {
52
52
}
53
53
// Find transform matrices while we're at it...
54
54
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++) {
57
57
basis[i].reduce_by (basis[j]);
58
58
}
59
59
basis[i].normalize ();
60
- basis[i] = vec<base>(
61
- basis[i][std::slice (n, n, 1 )]
62
- ) * (base (1 ) / basis[i][i]);
63
60
}
64
61
auto T = matrix::from_range (basis_init);
65
62
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
+ }
66
69
return std::tuple{T, Tinv, charps};
67
70
} else {
68
71
return charps;
Original file line number Diff line number Diff line change @@ -28,9 +28,11 @@ namespace cp_algo::linalg {
28
28
29
29
matrix& operator *=(base t) {for (auto &it: *this ) it *= t; return *this ;}
30
30
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;}
31
33
32
34
// 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;}
34
36
35
37
void read () {
36
38
for (auto &it: *this ) {
@@ -227,7 +229,7 @@ namespace cp_algo::linalg {
227
229
};
228
230
}
229
231
}
230
- private:
232
+
231
233
// To be called after a gaussian elimination run
232
234
// Sorts rows by pivots and classifies
233
235
// variables into pivots and free
Original file line number Diff line number Diff line change 1
1
// @brief Pow of Matrix (Frobenius)
2
2
#define PROBLEM " https://judge.yosupo.jp/problem/pow_of_matrix"
3
3
#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
6
5
#include " cp-algo/linalg/frobenius.hpp"
7
6
#include < bits/stdc++.h>
8
7
You can’t perform that action at this time.
0 commit comments