题目链接

传送门

思路

十进制矩阵快速幂。

代码

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson (rt<<1),L,mid
#define rson (rt<<1|1),mid + 1,R
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("/home/dillonh/CLionProjects/Dillonh/in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 1000000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int MOD;
char s[maxn]; struct matrix {
int a[2][2];
matrix operator * (const matrix& x) const {
matrix b;
for(int i = 0; i < 2; ++i) {
for(int j = 0; j < 2; ++j) {
b.a[i][j] = 0;
for(int k = 0; k < 2; ++k) {
b.a[i][j] = (b.a[i][j] + 1LL * a[i][k] * x.a[k][j] % MOD) % MOD;
}
}
}
return b;
}
}x, A[10]; matrix qpow(matrix x, int n) {
matrix b;
memset(b.a, 0, sizeof(b.a));
b.a[0][0] = b.a[1][1] = 1;
while(n) {
if(n & 1) b = b * x;
x = x * x;
n >>= 1;
}
return b;
} int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
memset(x.a, 0, sizeof(x.a));
scanf("%d%d%d%d", &x.a[0][1], &x.a[0][0], &A[1].a[0][0], &A[1].a[1][0]);
A[1].a[0][1] = 1;
scanf("%s%d", s + 1, &MOD);
for(int i = 2; i <= 9; ++i) A[i] = A[i-1] * A[1];
int n = strlen(s + 1);
matrix ans = A[s[1]-'0'];
for(int i = 2; i <= n; ++i) {
ans = qpow(ans, 10);
if(s[i] > '0') {
ans = ans * A[s[i]-'0'];
}
}
ans = x * ans;
printf("%d\n", ans.a[0][1]);
return 0;
}

generator 1(2019年牛客多校第五场B题+十进制矩阵快速幂)的更多相关文章

  1. Distance(2019年牛客多校第八场D题+CDQ+树状数组)

    题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...

  2. 2019年牛客多校第四场 B题xor(线段树+线性基交)

    题目链接 传送门 题意 给你\(n\)个基底,求\([l,r]\)内的每个基底是否都能异或出\(x\). 思路 线性基交板子题,但是一直没看懂咋求,先偷一份咖啡鸡板子写篇博客吧~ 线性基交学习博客:传 ...

  3. Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串. 思路 参考代码:传送门 本质不同的回文子串肯定是要 ...

  4. Find the median(2019年牛客多校第七场E题+左闭右开线段树)

    题目链接 传送门 题意 每次往集合里面添加一段连续区间的数,然后询问当前集合内的中位数. 思路 思路很好想,但是卡内存. 当时写的动态开点线段树没卡过去,赛后机房大佬用动态开点过了,\(tql\). ...

  5. Explorer(2019年牛客多校第八场E题+线段树+可撤销并查集)

    题目链接 传送门 题意 给你一张无向图,每条边\(u_i,v_i\)的权值范围为\([L_i,R_i]\),要经过这条边的条件是你的容量要在\([L_i,R_i]\),现在问你你有多少种容量使得你可以 ...

  6. 2019年牛客多校第三场 F题Planting Trees(单调队列)

    题目链接 传送门 题意 给你一个\(n\times n\)的矩形,要你求出一个面积最大的矩形使得这个矩形内的最大值减最小值小于等于\(M\). 思路 单调队列滚动窗口. 比赛的时候我的想法是先枚举长度 ...

  7. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  8. 2020牛客多校第八场K题

    __int128(例题:2020牛客多校第八场K题) 题意: 有n道菜,第i道菜的利润为\(a_i\),且有\(b_i\)盘.你要按照下列要求给顾客上菜. 1.每位顾客至少有一道菜 2.给顾客上菜时, ...

  9. 2019牛客多校第五场 B - generator 1 矩阵快速幂+十倍增+二进制倍增优化

    B - generator 1 题意 给你\(x_{0}.x_{1}.a.b.b.mod\),根据\(x_{i} = a*x_{i-1} + b*x_{i-2}\)求出\(x_{n}\) 思路 一般看 ...

随机推荐

  1. Hello 2019 D 素因子贡献法计算期望 + 概率dp + 滚动数组

    https://codeforces.com/contest/1097/problem/D 题意 给你一个n和k,问n经过k次操作之后留下的n的期望,每次操作n随机变成一个n的因数 题解 概率dp计算 ...

  2. PKUSC2018题解

    PKUSC2018题解 真实排名 分别考虑第\(i\)个人翻倍和不翻倍的情况,组合数算一下即可,务必注意实现细节. 代码 最大前缀和 设\(sum_s\)表示集合\(\sum_{i\in s} a_i ...

  3. [E] Shiro 官方文档阅读笔记 The Reading Notes of Shiro's Offical Docs

    官方文档: https://shiro.apache.org/reference.html https://shiro.apache.org/java-authentication-guide.htm ...

  4. oracle-报错 RMAN-03002,RMAN-06172

    RMAN> restore standby controlfile from "/data/oracle/contral.ctl"; Starting restore at ...

  5. js原型和原型链,以及__proto__、prototype属性

    __proto__和prototype属性: 1.__proto__属性: 在JS里,万物皆对象(函数是对象.原型也是对象...).对象都具有属性__proto__,这个属性会指向该对象的原型. 2. ...

  6. centos 7 安装python3 & pip3

    1.安装python3 https://www.cnblogs.com/Trees/p/7497482.html 2.解决:python ModuleNotFoundError: No module ...

  7. 【MySQL】binlog2sql

    binlog2sql 1.安装 shell> git clone https://github.com/danfengcao/binlog2sql.git && cd binlo ...

  8. [转帖]【译】RAID的概念和RAID对于SQL性能的影响

    [译]RAID的概念和RAID对于SQL性能的影响 https://www.cnblogs.com/VicLiu/p/11479427.html 简介 我们都听说过RAID,也经常作为SQL DBA. ...

  9. docker系列之二:构建docker容器

    1.创建在FlaskApp/app中创建Flask项目: 2.生成web项目所需的运行环境:pip3 freeze > ../requirements.txt 3.编辑Dockerfile: # ...

  10. torch.max

    torch.max() torch.max(input) -> Tensor Explation: ​ Returns the maximum value of all elements in ...