题意:求\(\sum_{i=0}^{n-1}a_ib_i\)

其中,\(a_i=A_xa_{i-1}+A_y,b_i=B_xb_{i-1}+B_y\)

构造矩阵分别维护\(a_ib_i,a_i,b_i,A_yB_y,A_y,B_y,S_i\)

\[\begin{bmatrix}
a_ib_i \\ a_i \\ bi \\ A_yB_y \\ A_y \\ B_y \\ S_i\\
\end{bmatrix} = \begin{bmatrix}
A_xB_x & A_xB_y & A_yB_x & 1 & 0 & 0 & 0 \\
0 & A_x & 0 & 0 & 1 & 0 & 0 \\
0 & 0 & B_x & 0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 \\
1 & 0 & 0 & 0 & 0 & 0 & 1 \\
\end{bmatrix} \begin{bmatrix}
a_{i-1}b_{i-1} \\ a_{i-1} \\ b_{i-1} \\ A_yB_y \\ A_y \\ B_y \\ S_{i-1}\\
\end{bmatrix}
\]

那么\(S_n\)即为所求

#include<bits/stdc++.h>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define println(a) printf("%lld\n",(ll)a)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct Matrix{
ll mt[9][9],r,c;
void init(int rr,int cc,bool flag=0){
r=rr;c=cc;
memset(mt,0,sizeof mt);
if(flag) rep(i,1,r) mt[i][i]=1;
}
Matrix operator * (Matrix rhs){
Matrix ans; ans.init(r,rhs.c);
rep(i,1,r){
rep(j,1,rhs.c){
int t=max(r,rhs.c);
rep(k,1,t){
ans.mt[i][j]+=(mt[i][k]*rhs.mt[k][j])%mod;
ans.mt[i][j]=(ans.mt[i][j])%mod;
}
}
}
return ans;
}
};
Matrix fpw(Matrix A,ll n){
Matrix ans;ans.init(A.r,A.c,1);
while(n){
if(n&1) ans=ans*A;
n>>=1;
A=A*A;
}
return ans;
}
ll a0,ax,ay,b0,bx,by;
ll n;
ll bas2[8],base[8][8];
int main(){
while(cin>>n){
cin>>a0>>ax>>ay;
cin>>b0>>bx>>by;
if(n==0){
println(0);
continue;
}
bas2[1]=(a0%mod)*(b0%mod)%mod;bas2[2]=a0%mod;bas2[3]=b0%mod;bas2[4]=(ay%mod)*(by%mod)%mod;
bas2[5]=ay%mod;bas2[6]=by%mod; bas2[7]=0;
memset(base,0,sizeof base);
base[1][1]=(ax%mod)*(bx%mod)%mod;base[1][2]=(ax%mod)*(by%mod)%mod;base[1][3]=(ay%mod)*(bx%mod)%mod;base[1][4]=1;
base[2][2]=ax%mod;base[2][5]=1;
base[3][3]=bx%mod;base[3][6]=1;
base[4][4]=1;
base[5][5]=1;
base[6][6]=1;
base[7][1]=1;base[7][7]=1;
Matrix A; A.init(7,7);
rep(i,1,7)rep(j,1,7) A.mt[i][j]=base[i][j];
Matrix b; b.init(7,1);
rep(i,1,7) b.mt[i][1]=bas2[i];
Matrix res=fpw(A,n)*b;
println(res.mt[7][1]);
}
return 0;
}

HDU - 4686 函数积的前缀和的更多相关文章

  1. Master of Phi (欧拉函数 + 积性函数的性质 + 狄利克雷卷积)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6265 题目大意:首先T是测试组数,n代表当前这个数的因子的种类,然后接下来的p和q,代表当前这个数的因 ...

  2. HDU 4686 Arc of Dream(矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...

  3. hdu 4746 Mophues 莫比乌斯反演+前缀和优化

    Mophues 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<=n, 1<=b<=m) 有Q组数据:(n, m, ...

  4. Hdu 4311-Meeting point-1 曼哈顿距离,前缀和

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4311 Meeting point-1 Time Limit: 2000/1000 MS (Java/Oth ...

  5. HDU 6186 CS Course(前缀+后缀)

    http://acm.hdu.edu.cn/showproblem.php?pid=6186 题意:给出n个数,共有n次询问,每次询问给出一个数p,求除去第p个数后的n-1个数的&.|.^值. ...

  6. hdu 4686 Arc of Dream(矩阵快速幂)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...

  7. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  8. 2016 ACM/ICPC亚洲区大连站 F - Detachment 【维护前缀积、前缀和、二分搜索优化】

    F - Detachment In a highly developed alien society, the habitats are almost infinite dimensional spa ...

  9. LightOJ-1007-Mathematically Hard-欧拉函数打表+前缀和+预处理

    Mathematically some problems look hard. But with the help of the computer, some problems can be easi ...

随机推荐

  1. 面试题:Java必知必会:异常机制详解 背1

    一.Java异常概述 在Java中,所有的事件都能由类描述,Java中的异常就是由java.lang包下的异常类描述的. Trowable是所有异常的超类.  他的常用方法printStackTrec ...

  2. APP前端开发时应注意的一些问题

    在做APP前端开发时应注意的一些问题 在整个app开发流程中,app前端开发是一个必不可少的环节,也是一个在app开发过程中重量级的角色.说到这,那么在app应用的前端开发中,又要注意什么问题呢?一. ...

  3. 3.SELECT 语句

    SELECT 语句用于从表中选取数据. 结果被存储在一个结果表中(称为结果集). SQL SELECT 语法 SELECT 列名称 FROM 表名称 以及: SELECT * FROM 表名称 注释: ...

  4. aspx页面上输出xml的问题

    在aspx页面上输出xml,需要在后台输出编码格式和编码类型,如下代码: Response.Charset = "utf-8";//格式Response.ContentType = ...

  5. c++(重载等号=操作为深拷贝)

    // ConsoleApplication19.cpp : 定义控制台应用程序的入口点. // #pragma warning(disable:4996) #include "stdafx. ...

  6. rest-framework之序列化组件

    一:django自带序列化组件 Django内置的serializers(把对象序列化成json字符串) from django.core import serializers def test(re ...

  7. Request[]与Request.Params[] 差别

    Request[]与Request.Params[] ,这二个属性都可以让我们方便地根据一个KEY去[同时搜索]QueryString.Form.Cookies 或 ServerVariables这4 ...

  8. HTML & CSS设计与构建网站 ([美]达科特) PDF原版​

    HTML & CSS 设计与构建网站采用有别于许多传统编程书籍的新颖编排方式,将使您收到事半功倍的学习效果.每一页都在短小精悍的示例代码的引导下,简明直观.直截了当地阐述一个新主题. < ...

  9. Vue watch用法

    Vue.js 提供了一个方法 watch,它用于观察Vue实例上的数据变动.对应一个对象,键是观察表达式,值是对应回调.值也可以是方法名,或者是对象,包含选项. 例如,同一个组件切换时,不会触发生命周 ...

  10. C# 属性与字段

    属性和字段的区别: 属性是逻辑字段,是字段的扩展,并不占用实际的内存:而字段占用内存空间. 属性可以被其他类访问:而非public的字段不能被直接访问. 属性可以对接受的数据在范围上做限定:而字段不能 ...