718C Sasha and Array】的更多相关文章

传送门 题目 Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l r x — increase all integers on the segment from l to r by values x; 2 l r — find , where f(x) is the x-th Fibonacci number.…
线段树. 线段树维护区间矩阵和,操作都是最简单的线段树.$lazy$标记不要记录乘了几次,直接记录乘了几次之后的矩阵就可以了,不然每次下传的时候再算一遍时间复杂度会提高. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include…
传送门 解题思路: 这道题给了我们一个崭新的角度来看线段树. 我们常常使用的线段树是维护区间的函数的. 这里呢,提示我们线段树其实还可以维护递推. 美好的矩阵递推性质支持了这一功能. 或者说,对于递推项求和,可以使用线段树维护矩阵. 区间向前递推可以用懒惰标记记录递推矩阵. 区间的查询可以是子节点矩阵和. 这其实也是满足分配率的. 最后pushup,pushdown搞一搞就好了. 代码(闲来无事卡常码风突变): #include<cstdio> #include<cstring>…
传送门 Solution 用线段树维护矩阵 第一个操作相当于区间乘 第二个操作相当于区间求和 Code  #include<bits/stdc++.h> #define ll long long #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'…
C. Sasha and Array time limit per test:5 seconds memory limit per test:256 megabytes input:standard input output: standard output Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l…
题目链接: E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types:…
Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l r x …
C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$opt==1$时,对$[L,R]$全部加x,$opt==2$时,对$[L,R]$求$\sum_{i=L}^{R}Fibonacc(a_{i})$. 题解: 线段树+矩阵快速幂. 在每个线段树存一个转移矩阵,然后YY即可. 代码: #include<cstdio> #include<cstrin…
CF719E. Sasha and Array 题意: 对长度为 n 的数列进行 m 次操作, 操作为: a[l..r] 每一项都加一个常数 C, 其中 0 ≤ C ≤ 10^9 求 F[a[l]]+F[a[l+1]]+...F[a[r]] mod 1e9+7 的余数 矩阵快速幂求斐波那契 矩阵满足乘法分配律和结合律! 所以可以每个节点维护矩阵/矩阵和,区间加相当于区间乘矩阵 注意:不要把快速幂写在里面,复杂度平添一个log.把\(B^C\)算出来之后传进去就好了 #include <iostr…
E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l r x - increase all integers on the segment from l…