2016年10月11日
摘要: 一道很好的题、 我们发现数据范围很GG 大概log n能过 然后考虑以下关于log的算法,再选几个小数据手玩一下 可以发现: 我们将k按二进制位考虑: 对于k的每一位, 如果为0, 那么每个and的两个数的二进制最后一位位一定不能均为1, 由此得出转移方程:f [ i ] [ 0 ] = f [ i 阅读全文
posted @ 2016-10-11 21:40 Absolutezero 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 递推式:f [ n ] =8 f [ n - 1] + 3f [ n - 2 ] + f [ n - 3 ] 由:f [ n - 1] + f [ n - 2 ] + f [ n - 3 ] 需要得到: f [ n ] + f [ n ] + f [ n ] 根据矩乘原理(怎么乘的)构造转移矩阵: 阅读全文
posted @ 2016-10-11 20:47 Absolutezero 阅读(400) 评论(0) 推荐(0) 编辑
  2016年10月10日
摘要: 首先,对于所有从x能到达y的路径中,限重越大越好 因此我们用Kruskal最大生成树得到一片森林(不一定都联通) 之后dfs维护森林的深度和LCA的预处理limit[x][0](x向上跳2^i步的边权最小值) 对于每个询问,求x和y到lca的边权最小值即可 1 #include<cstdio> 2 阅读全文
posted @ 2016-10-10 22:01 Absolutezero 阅读(241) 评论(0) 推荐(0) 编辑
  2016年10月8日
摘要: 火星文Trie插入 对应英文存到数组查询 对于每一个火星文句子,拆成若干单词分别在Trie树中查询 PS:开数组的话要开大,大概100W左右,不然会一直RE…… 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 #defi 阅读全文
posted @ 2016-10-08 21:50 Absolutezero 阅读(198) 评论(0) 推荐(0) 编辑
  2016年10月6日
摘要: 树链剖分: dfs1:找重边(size,son,deep) dfs2:建链&&建线段树(top,pos)f:当前重链深度最浅的点 一个点到根的路径就被划分为log个区间,然后链修改就相当于log个区间的修改 每次修改x到y, 1)如果x,y在一条重链上,直接修改 2)不在,则使x,y分别向上蹦,直到 阅读全文
posted @ 2016-10-06 15:38 Absolutezero 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 这道题我们发现每个串的长度只有60 所以对于第一个串(或者选一个你喜欢的)枚举子串分别与其他串KMP匹配 注意长度相等时字典序最小&&长度<3时 no significant commonalities 1 #include<cstdio> 2 #include<cstring> 3 using n 阅读全文
posted @ 2016-10-06 11:31 Absolutezero 阅读(223) 评论(0) 推荐(0) 编辑
  2016年10月5日
摘要: Trie树 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int trie[300010][30],sum[300010],cnt,n; 5 char s[1010][25]; 6 void insert(int le 阅读全文
posted @ 2016-10-05 17:06 Absolutezero 阅读(107) 评论(0) 推荐(0) 编辑
摘要: KMP模板题 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int pre[1000010],m[1000010]; 5 char p[1000010],q[1000010]; 6 int KMP(int l1,int 阅读全文
posted @ 2016-10-05 14:02 Absolutezero 阅读(129) 评论(0) 推荐(0) 编辑
  2016年10月4日
摘要: 矩乘快速幂入门 题目已经把题解讲得很清楚了 1 #include<cstdio> 2 #include<cstring> 3 #include<cassert> 4 #include<algorithm> 5 using namespace std; 6 #define p 10000 7 #def 阅读全文
posted @ 2016-10-04 20:53 Absolutezero 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 树上单点修改,子树查询 可以在这棵树的dfs序上建线段树维护 PS:modify、query的时候传入x的dfs序即可 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 const int N=100010,M=40001 阅读全文
posted @ 2016-10-04 16:17 Absolutezero 阅读(154) 评论(0) 推荐(0) 编辑