generator 1(2019年牛客多校第五场B题+十进制矩阵快速幂)
题目链接
思路
十进制矩阵快速幂。
代码
#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题+十进制矩阵快速幂)的更多相关文章
- Distance(2019年牛客多校第八场D题+CDQ+树状数组)
题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...
- 2019年牛客多校第四场 B题xor(线段树+线性基交)
题目链接 传送门 题意 给你\(n\)个基底,求\([l,r]\)内的每个基底是否都能异或出\(x\). 思路 线性基交板子题,但是一直没看懂咋求,先偷一份咖啡鸡板子写篇博客吧~ 线性基交学习博客:传 ...
- Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串. 思路 参考代码:传送门 本质不同的回文子串肯定是要 ...
- Find the median(2019年牛客多校第七场E题+左闭右开线段树)
题目链接 传送门 题意 每次往集合里面添加一段连续区间的数,然后询问当前集合内的中位数. 思路 思路很好想,但是卡内存. 当时写的动态开点线段树没卡过去,赛后机房大佬用动态开点过了,\(tql\). ...
- Explorer(2019年牛客多校第八场E题+线段树+可撤销并查集)
题目链接 传送门 题意 给你一张无向图,每条边\(u_i,v_i\)的权值范围为\([L_i,R_i]\),要经过这条边的条件是你的容量要在\([L_i,R_i]\),现在问你你有多少种容量使得你可以 ...
- 2019年牛客多校第三场 F题Planting Trees(单调队列)
题目链接 传送门 题意 给你一个\(n\times n\)的矩形,要你求出一个面积最大的矩形使得这个矩形内的最大值减最小值小于等于\(M\). 思路 单调队列滚动窗口. 比赛的时候我的想法是先枚举长度 ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 2020牛客多校第八场K题
__int128(例题:2020牛客多校第八场K题) 题意: 有n道菜,第i道菜的利润为\(a_i\),且有\(b_i\)盘.你要按照下列要求给顾客上菜. 1.每位顾客至少有一道菜 2.给顾客上菜时, ...
- 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}\) 思路 一般看 ...
随机推荐
- machine_math2
1. 2. 3.拉格朗日对偶??? 弱对偶 强对偶: <1>slater条件(强对偶的充分条件): 1.凸函数. 2.存在一个可行解满足不等式成立. 4.KKT条件
- Linux性能优化实战学习笔记:第四十六讲
一.上节回顾 不知不觉,我们已经学完了整个专栏的四大基础模块,即 CPU.内存.文件系统和磁盘 I/O.以及网络的性能分析和优化.相信你已经掌握了这些基础模块的基本分析.定位思路,并熟悉了相关的优化方 ...
- [LeetCode] 364. Nested List Weight Sum II 嵌套链表权重和之二
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- 关于Adobe Premiere Pro视音频不同步的解决方法
在Potplayer和系统播放器都正常 但Pr里面就是音画不同步 原因是Pr识别错误,让音频比视频快了,这时要将视频后拉一点就ok了
- java web开发入门六(spring mvc)基于intellig idea
spring mvc ssm=spring mvc+spring +mybatis spring mvc工作流程 1A)客户端发出http请求,只要请求形式符合web.xml文件中配置的*.actio ...
- logback&log4j异步日志配置
logback 原始配置 配置 appender, 控制文件的滚动方式,日志的输出格式. <appender name="method-time-appender" clas ...
- Github问题:fatal: unable to access 'https://github.com/LIU-HONGYANG/Algorithm.git/': The requested URL returned error: 403
在向服务器push之后,出现如下问题: The requested URL returned error: 403 解决路径如下: 参考文章: https://stackoverflow.com/qu ...
- 【排错】springboot项目,启动报An attempt was made to call the method com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder; but it does not exist.
pom文件新引入: <dependency> <groupId>com.google.code.gson</groupId> ...
- Deep Learning专栏--强化学习之MDP、Bellman方程(1)
本文主要介绍强化学习的一些基本概念:包括MDP.Bellman方程等, 并且讲述了如何从 MDP 过渡到 Reinforcement Learning. 1. 强化学习基本概念 这里还是放上David ...
- C++分治策略实现二分搜索
问题描述: 给定已排好序的n个元素组成的数组,现要利用二分搜索算法判断特定元素x是否在该有序数组中. 细节须知: (1)由于可能需要对分治策略实现二分搜索的算法效率进行评估,故使用大量的随机数对算法进 ...