hdu-5068 Harry And Math Teacher
http://acm.hdu.edu.cn/showproblem.php?pid=5068
题意:给你n层楼,每层楼有两个门,
m个操作 Q = 1 表示 第 x 层楼 第y个门到第x+1层楼的第z个门的路改变其状态(初始每条路都可以走的)
* Q = 0 表示询问第x层楼到第y层楼的方式有多少种
题解:线段数 + 矩阵乘法
因为只有两个门所以我们可以把第x层楼到第x+1层楼标记状态
/**单纯的从某层楼到某层楼,可以用一个递推,然后可以演化成矩阵如下* 0 1* ————*0 |1 1*1 |1 1*如果在更新的话只需更改某个门到某个门的标记即可,即异或1,就可以改变其状态,即矩阵的值有所改变;*此题比较裸地线段树(插点问线问题)*根据矩阵的结合律计算即可
**/#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod = 1000000007;
#define M 50010
#define lson(st) (st<<1)
#define rson(st) ((st<<1)|1)
int x,y,z;
struct matrix{LL m[2][2];matrix(){memset(m,0,sizeof(m));}matrix operator * (const matrix &a) const{matrix c;for(int i = 0;i < 2;i ++)for(int j = 0;j < 2;j ++)for(int k = 0;k < 2;k ++)c.m[i][j] = (c.m[i][j] + m[i][k]*a.m[k][j]) % mod;return c;}
};
struct Node{matrix s;int l,r;
}node[M<<3];
void Pushup(int st){node[st].s= node[lson(st)].s * node[rson(st)].s;
}
void build(int l,int r,int st){node[st].l = l;node[st].r = r;if(l == r){for(int i = 0;i < 2;i++)for(int j = 0;j < 2;j++)node[st].s.m[i][j] = 1;return ;}int mid = (l + r) >> 1;build(l,mid,lson(st));build(mid+1,r,rson(st));Pushup(st);
}
void update(int x,int st){if(node[st].l == node[st].r){node[st].s.m[y][z] ^= 1;return ;}int mid = (node[st].l + node[st].r) >> 1;if(x <= mid) update(x,lson(st));else update(x,rson(st));Pushup(st);
}
matrix Query(int L,int R,int st){if(node[st].l >= L && node[st].r <= R)return node[st].s;matrix ans;ans.m[0][0] = ans.m[1][1] = 1;int mid = (node[st].l + node[st].r) >> 1;if(L <= mid) ans = ans * Query(L,R,lson(st));if(R > mid) ans = ans * Query(L,R,rson(st));return ans;
}
int main()
{int n,m,q;while(~scanf("%d%d",&n,&m)){build(1,n-1,1);for(int i = 0;i < m;i++){cin >> q;if(q == 1){cin >> x >> y >> z;y--,z--;update(x,1);}else {cin >> x >> y;matrix res = Query(x,y-1,1);LL ans = 0;for(int k = 0;k < 2;k++)for(int j = 0;j < 2;j++)ans = (ans + res.m[k][j]) % mod;cout << ans << endl;}}}return 0;
}
hdu-5068 Harry And Math Teacher相关推荐
- HDU 5066 Harry And Physical Teacher(物理题)
HDU 5066 Harry And Physical Teacher 思路:利用物理里面的动量守恒公式,由于保证小车质量远大于小球,所以可以把小车质量当成无穷大带进去,得到答案为2 * v0 - v ...
- hdu 5435 A serious math problem(数位dp)
题目链接:hdu 5435 A serious math problem 裸的数位dp. #include <cstdio> #include <cstring> #inclu ...
- hdu 5615 Jam's math problem(判断是否能合并多项式)
方法一:由十字相乘相关理论我们能知道,如果要有p,k,q,m,那么首先要有解,所以b*b-4*a*c要>0,然而因为p,k,q,m是正整数,所以代表x1,x2都是有理数,有理数是什么鬼呢?就是解 ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 在吴神的帮助下才明白如何构造矩阵,还是好弱啊. 此处盗一张图 1 #include <io ...
- HDU 1757 A Simple Math Problem(矩阵快速幂)
题目链接 题意 :给你m和k, 让你求f(k)%m.如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + -- ...
- HDU - 5974 A Simple Math Problem 题解
D - Simple Math Problem 戳上方进入原题哟~ 题目大意 给一个数 a,b. 让你求满足一下条件的 X,Y: X+Y = a LCM(X,Y) = b 解析 题目给出时间限制1s, ...
- HDU 1757 A Simple Math Problem
Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...
- hdu 1757 A Simple Math Problem 构造矩阵
题意:函数f(x), 若 x < 10 f(x) = x. 若 x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + ...
- HDU - 1757 A Simple Math Problem(矩阵快速幂,水题)
题目链接:点击查看 题目大意:实现公式: f(x)=x,x<10 f(x)=a0*f(x-1)+a1*f(x-2)+--+a9*f(x-10) 题目给出a0~a9,一个n和一个m,要求输出f(n ...
最新文章
- AppiumForWin安装
- 计算机文件系统小结,文件系统总结.doc
- Windows10内置Linux子系统初体验
- 多个项目共享一个app.config 的解决办法 (转)
- Java 基础学习(Markdown语法)
- 2018年最后一个月最值得关注的13个优质公号
- Java IO流总结
- 阿里云centos云服务器 - 网站搭建教程
- easyui datagrid 列隐藏和显示
- 2018微博词云项目深度解析
- java解惑之最后的笑声
- 用Python分析44万条数据,揭秘如何成为网易云音乐评论区的网红段子手
- mysql怎么做纵表,本文实例讲述了MySQL横纵表相互转化操作实现方法。分享给大家供大家参考,具体如下:先创建一个成绩表(纵表)create table user_scor...
- 计算机考试后的感想,计算机考试的感想
- Tensorflow读取图片并转换成张量
- 求水洼的问题——深度优先算法
- linux之cut的使用
- CC1120 Sub-1G 无线射频收发器 驱动开发
- python入门教学视频材料整理-免费
- 快捷录播服务器怎么显示时间,全场景高清录播服务器 自动高清录播系统 方便携带 搭建快捷...
热门文章
- 盘它:1200 天积淀,超 750 篇干货,为你甄选这 100 + 篇精华!
- 第三次作业-结对编程
- Java Socket编程如何建立两者关系
- 关于类的非静态函数指针成员变量
- 深入浅出,ARCore开发原理
- Linux文件创建时间
- OpenCV之mixChannels()函数使用说明
- 巧妙解决:access denied (javax.management.MBeanTrust...
- 路由器的×××流量过滤
- factors to consider about the publications