RT,谁可以提出使这个代码更快的方法或是指出我这个哪里时间复杂度高了?谢谢!
#include<iostream>
#include<array>
#include<algorithm>
#include<cmath>
#define block array<array<gg,3>,3>
#define reg register
using namespace std;
using gg=long long;
block tp={1,0,1,1,0,0,0,1,0},ans,res;
const gg mod=1000000007;
void cheng(const block &x,const block &y)
{
res[0][0]=res[0][1]=res[0][2]=res[1][0]=res[1][1]=res[1][2]=res[2][0]=res[2][1]=res[2][2]=0;
for(reg gg k=0;k<3;k++)
{
for(reg gg i=0;i<3;i++)
{
for(reg gg j=0;j<3;j++)
{
res[i][j]+=x[i][k]*y[k][j]%mod;
}
}
}
return ;
}
void qpow(reg block x,reg gg y)
{
ans[0][1]=ans[0][2]=ans[1][0]=ans[1][2]=ans[2][0]=ans[2][1]=0;
ans[0][0]=ans[1][1]=ans[2][2]=1;
while(y)
{
if(y&1)
{
cheng(ans,x);
ans=res;
}
y>>=1;
cheng(x,x);
x=res;
}
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
reg gg t,n;
cin>>t;
for(reg gg T=1;T<=t;T++)
{
cin>>n;
qpow(tp,n-3);
cout<<(ans[0][0]+ans[0][1]+ans[0][2])%mod<<'\n';
}
return 0;
}