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}\) 思路 一般看 ...
随机推荐
- stringstream字符串流的妙用
现在有一个数组,其值为从1到10000的连续增长的数字.出于某次偶然操作,导致这个数组中丢失了某三个元素,同时顺序被打乱,现在需要你用最快的方法找出丢失的这三个元素,并且将这三个元素根据从小到大重新拼 ...
- [LeetCode] 103. Binary Tree Zigzag Level Order Traversal 二叉树的之字形层序遍历
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- Matlab:Toeplitz矩阵-向量乘法的快速傅里叶(FFT)算法
一.$\tt Toeplitz$矩阵与循环($\tt Circulant$)矩阵 定义 为$n\times n$阶循环矩阵. 定义 $T_n(i,j)=t_{j-i} $ 为$n\times n$ ...
- 关于Windows自动化卸载软件的思路
思路 关于控制面板“卸载”关联到的exe是这样的: 注册表:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall ...
- oracle--表空间故障
一,错误问题描述 ERROR: ORA: cannot identify - see DBWR trace file ORA: data : '/u01/oracle/TEST/oratmp01/te ...
- LeetCode 75. Sort Colors (颜色分类):三路快排
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the ...
- 【操作系统之十四】iptables扩展模块
1.iprange 使用iprange扩展模块可以指定"一段连续的IP地址范围",用于匹配报文的源地址或者目标地址.--src-range:匹配报文的源地址所在范围--dst-ra ...
- 使用Windows的Linux子系统搭建嵌入式开发环境
亲,都9102年了,还在用VMware跑嵌入式交叉编译链吗? 北京时间2019年6月13日,Windows 10发布预览版本18917.版本的主要功能是Linux子系统(windows sub ...
- Qt 窗口操作函数(置顶、全屏,最大化最小化按钮设置等)
一.窗口置顶 与 取消置顶 void MainWindow::on_windowTopButton_clicked() { if (m_flags == NULL) { m_flags = windo ...
- firefly rk3399 增加 HL-340 驱动(编译内核)
前言:新下载了firefly rk3399 ubuntu固件16.04,但是发现没有HL-340 USB转串口的驱动,而机器人底盘驱动是HL-340的,所以一直提示无法找到设备驱动. 由于没有技术支持 ...