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: 1 l r…
E. Sasha and Array 这个题目没有特别难,需要自己仔细想想,一开始我想了一个方法,不对,而且还很复杂,然后lj提示了我一下说矩阵乘,然后再仔细想想就知道怎么写了. 这个就是直接把矩阵放到线段树里面去了. 注意优化,降低复杂度. #include <cstring> #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #inclu…
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…
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | fn-1 | */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef __int64 LL; LL mod = 1e9 + ; struct data {…
题目链接 分析:矩阵快速幂+线段树 斐波那契数列的计算是矩阵快速幂的模板题,这个也没什么很多好解释的,学了矩阵快速幂应该就知道的东西= =这道题比较巧妙的在于需要用线段树来维护矩阵,达到快速查询区间斐波那契数列和的目的.这道题极为卡常数,我TLE了不知道多少发,才在赛后过了这道题. 我尝试下来,发现矩阵乘法的写法极为重要,我就是因为用了三层循环来写矩阵乘法导致了悲剧的TLE,一直卡在了第17组数据.我百度了网上别的矩阵快速幂的写法才过了这道题. 还有涨智识的地方是不要随意memset.我原来的矩…
如果mod是质数就好做了,但是做除法的时候对于合数mod可能没有逆元.所以就只有存一下mod的每个质因数(最多9个)的幂,和剩下一坨与mod互质的一部分.然后就能做了.有点恶心. CODE #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 100005; const int MAXP = 9; int n, q, a[MAXN], p[MAXP], cnt, mod, phi…
思路: dfs序其实是很水的东西.  和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的时候, 我们要查询一下赋值前子树最小值是不是0, 如果是的话, 要让该子树父节点变成0, 否则变0的信息会丢失. 细节参见代码: #include <cstdio> #include <cstring> #include <algorithm> #include <i…
A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j], 将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][k]+B[k][j]).非法的情况标记为-INF,用倍增加速. #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; ; int n; typedef int MType; struct Matrix {…
/* 题意:给定一个长度为n的序列a. 两种操作: 1.给定区间l r 加上某个数x. 2.查询区间l r sigma(fib(ai)) fib代表斐波那契数列. 思路: 1.矩阵操作,由矩阵快速幂求一个fib数根据矩阵的乘法结合率,A*C+B*C=(A+B)*C; 这样可以通过线段树维护某个区间2*1矩阵的和. 2.时限卡的紧...用我的矩阵乘法板子TLE了.所以把板子里边的三重循环改成手工公式... 3.注意(a+b)%mod.这种,改成if(a+b>=mod)a+b-mod这种形式时间几乎…
Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选择某位小数进行四舍五入,最多做\(t(t \le 10^9)\)次. 求最大的数. 思路 每次必然找小数部分能进行四舍五入的最高位,并且四舍五入的位置是递增的. 注意:99.5这样的数据,最高位会进位. 代码 A. Efim and Strange Grade C. Sasha and Array…