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
| #include<bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;i++) using namespace std;
typedef long long LL;
const int maxm=1e5+5; const LL mo=1e9+7;
struct ARR{ LL n[3][3]; }; ARR re; ARR operator * (const ARR &a,const ARR &b) { fo(i,0,2) fo(j,0,2) { re.n[i][j]=0; fo(k,0,2) (re.n[i][j]+=a.n[i][k]*b.n[k][j])%=mo; } return re; }
int m; LL n,x[maxm];
ARR C,ans; void mi(LL y) { for(; y; y>>=1, C=C*C) if (y&1) ans=ans*C; }
int main() { scanf("%lld %d",&n,&m); fo(i,1,m) scanf("%d",&x[i]); x[++m]=n; sort(x+1,x+1+m); ans=(ARR){{{1,0,0},{0,0,0},{0,0,0}}}; x[0]=-1; fo(i,1,m) { LL len=x[i]-(x[i-1]+1); C=(ARR){{{1,2,1},{0,1,1},{1,2,2}}}; mi(len); if (i==m) break; C=(ARR){{{1,2,1},{0,1,1},{0,0,1}}}; ans=ans*C; } printf("%lld\n",ans.n[0][2]); }
|