摘要:
XOR and Favorite Number 这个题能改变成加法。 第三个while始终觉得区间变长了,看了一下午还是很难理解。 #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; typedef lon 阅读全文
摘要:
CodeForces 628E Zbazi in Zeydabad 这个树状数组很巧妙。 将$O(n^3)$降到$O(n^2logn)$。 每个对角线的加和相等,建在一棵树上。 #include <bits/stdc++.h> using namespace std; const int maxn 阅读全文
摘要:
记得分块还是大一时学的,后来就没怎么写过,趁此时机,再重新巩固一下此专题。 1.普通分块题目 POJ 3468 后悔没有学习这么优秀的代码,自己当年写的就是一坨屎。 #include <cstdio> #include <algorithm> #include <cmath> using names 阅读全文
摘要:
GuGuFishtion dls真厉害,快速求$\sum_{a=1}^n \sum_{b=1}^m gcd(a,b) $的个数,我想的方法是根据上节课dls讲的方法,要容过来容过去,这次不用了。 则$f[d]=(n/d)\times (m/d)$。 而$g[d]=f[d]-\sum_{d|x} g[ 阅读全文
摘要:
Werewolf 只考虑村民边,然后每个村民边求联通块,最后加狼边,看看两个端点在不在一个联通块里就可以了。 比赛的时候有点坑,思路正确,写歪了…… #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; ve 阅读全文
摘要:
Problem B. Harvest of Apples #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; typedef long long ll; const ll mod = 1e9 + 7; ll 阅读全文
摘要:
今天帮舍友做道笔试题,可惜只过了66.7%,怎么看算法都没有问题,后来想想应该是超时了。 题目如下: 题目就是给了这么个有向图,然后让你输出总共有几条链,并且输出最长的链的长度。 我当时想直接DFS统计,从入度为0开始统计,直到叶子节点结束,这是链的个数,最长路顺路就记了。 但是应该是超时了,虽然看 阅读全文
摘要:
Problem A. Ascending Rating 先学习一下单调队列与单调栈,其实和STL的也没啥区别,就是手动维护数组。 POJ 2823 #include <cstdio> #include <algorithm> using namespace std; const int maxn = 阅读全文
摘要:
CodeForces 628E CodeForces 617E CodeForces 618E CodeForces 620E dfs序+线段树+set存颜色T了。 我竟然没想到可以用long long来存颜色,这次吸取教训了。 #include <bits/stdc++.h> using name 阅读全文
摘要:
1.多重集的组合数 这里问题一般的描述为: 算法竞赛进阶指南上有详细的推导。 例题1: CF 451E Devu and Flowers 直接带公式,但本题 m 太大,先用Lucas对m取模,再转换成排列再乘以逆元就可以了。 #include <bits/stdc++.h> using namesp 阅读全文