-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.cpp
More file actions
100 lines (86 loc) · 2.13 KB
/
Matrix.cpp
File metadata and controls
100 lines (86 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef LOCAL
#include <debug.h>
#else
#define dbg(x...)
#endif
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;
template<typename T>
struct Matrix {
vector<vector<T>> mat;
ll n, m;
Matrix(ll _n, ll _m) : n(_n), m(_m) {
mat.resize(n, vector<T>(m, 0));
}
Matrix(const vector<vector<T>> &a) : n((ll)a.size()), m((ll)a[0].size()) {
mat = a;
}
Matrix operator * (const Matrix &b) const {
assert(m == b.n);
Matrix res(n, b.m);
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < b.m; j++) {
for (ll k = 0; k < m; k++) {
res.mat[i][j] += mat[i][k] * b.mat[k][j];
}
}
}
return res;
}
Matrix operator + (const Matrix &b) const {
assert(n == b.n && m == b.m);
Matrix res(n, m);
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
res.mat[i][j] = mat[i][j] + b.mat[i][j];
}
}
return res;
}
Matrix operator += (const Matrix &b) {
assert(n == b.n && m == b.m);
*this = (*this) + b;
return *this;
}
Matrix operator *= (const Matrix &b) {
assert(m == b.n);
*this = (*this) * b;
return *this;
}
Matrix pow(ll p) const {
assert(n == m);
Matrix res(n, n);
for (ll i = 0; i < n; i++) res.mat[i][i] = 1;
Matrix base = *this;
while (p) {
if (p & 1) res = res * base;
base = base * base;
p >>= 1;
}
return res;
}
};
void solve()
{
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
cerr << "Testcase No. - " << i << "\n";
solve();
}
return 0;
}