矩阵乘法模板--zhengjun

const int M=3;
using vec=array<int,M>;
using matrix=array<vec,M>;
#ifdef DEBUG
ostream& operator << (ostream &out,vec a){
	out<<'[';
	for(int x:a)out<<x<<',';
	return out<<']';
}
ostream& operator << (ostream &out,matrix a){
	out<<'[';
	for(vec x:a)out<<x<<',';
	return out<<']';
}
#endif
vec operator * (const vec &a,const matrix &b){
	static vec c;
	c.fill(0);
	for(int i=0;i<M;i++){
		for(int j=0;j<M;j++){
			c[j]=(c[j]+1ll*a[i]*b[i][j])%mod;
		}
	}
	return c;
}
matrix operator * (const matrix &a,const matrix &b){
	static matrix c;
	for(int i=0;i<M;i++)c[i]=a[i]*b;
	return c;
}
vec operator + (const vec &a,const vec &b){
	static vec c;
	for(int i=0;i<M;i++)c[i]=(a[i]+b[i])%mod;
	return c;
}
vec operator * (const vec &a,const int &k){
	static vec b;
	for(int i=0;i<M;i++)b[i]=1ll*a[i]*k%mod;
	return b;
}
posted @ 2023-08-09 16:39  A_zjzj  阅读(27)  评论(0编辑  收藏  举报