Skip to content

Commit 5fe35dc

Browse files
committed
add links
1 parent c7f4823 commit 5fe35dc

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

copypasta/bits.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func (b bitset) onesCount() (c int) {
236236
}
237237

238238
// 遍历所有 1 的位置
239+
// 如果对范围有要求,可在 f 中 return p < n
239240
func (b bitset) foreach(f func(p int) (Break bool)) {
240241
for i, v := range b {
241242
for ; v > 0; v &= v - 1 {

copypasta/graph_tree.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ func (*tree) subtreeSize(n, root int, g [][]int) {
135135

136136
// 每个节点的入出时间戳
137137
// 应用:可以 O(1) 判断 fa 是否为 v 的祖先节点(是否在根到 v 的路径上)
138-
// 例题 https://codeforces.com/contest/1328/problem/E
138+
// 例题 https://codeforces.com/problemset/problem/1328/E
139+
// 好题(需要充分利用入出时间戳的性质)https://codeforces.com/problemset/problem/1528/C
139140
// 给定一颗 n 个点的完全 k 叉树的先序遍历,还原这棵树 https://ac.nowcoder.com/acm/contest/9247/B
140141
// 先用 BFS 建树,然后 DFS 跑建好的树
141142
// 也可以不用 BFS,根据完全 k 叉树的性质直接建图:(点的范围从 0 到 n-1)
@@ -147,21 +148,22 @@ func (*tree) subtreeSize(n, root int, g [][]int) {
147148
func (*tree) inOutTimestamp(n, root int, g [][]int) {
148149
timeIn := make([]int, n)
149150
timeOut := make([]int, n)
151+
at := make([]int, n+1)
150152
clock := 0
151153
var f func(v, fa int)
152154
f = func(v, fa int) {
153155
clock++
154156
timeIn[v] = clock
157+
at[clock] = v
155158
for _, w := range g[v] {
156159
if w != fa {
157160
f(w, v)
158161
}
159162
}
160-
clock++
161163
timeOut[v] = clock
162164
}
163165
f(root, -1)
164-
isFa := func(fa, v int) bool { return timeIn[fa] < timeIn[v] && timeOut[v] < timeOut[fa] } // timeOut[v] 也可以写成 timeIn[v]
166+
isPa := func(pa, v int) bool { return timeIn[pa] < timeIn[v] && timeIn[v] <= timeOut[pa] }
165167

166168
{
167169
// 与深度时间戳结合,二分求某个子树在某个深度的节点范围
@@ -199,7 +201,7 @@ func (*tree) inOutTimestamp(n, root int, g [][]int) {
199201
_ = query
200202
}
201203

202-
_ = isFa
204+
_ = isPa
203205
}
204206

205207
// 树上最小路径覆盖,要求路径之间不相交,即每个顶点恰好被覆盖一次(路径长度可以为 0,即一个点)

copypasta/math.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func numberTheoryCollection() {
753753
}
754754
return
755755
}
756-
primeDivisors := func(x int) (primes []int) {
756+
primeDivisors := func(x int) (primes []int) { // primeFactorization 质因数分解
757757
for i := 2; i*i <= x; i++ {
758758
if x%i == 0 {
759759
for x /= i; x%i == 0; x /= i {
@@ -1079,6 +1079,31 @@ func numberTheoryCollection() {
10791079
_, _ = isSquareNumber, halfDivisors
10801080
}
10811081

1082+
// 初始化 Squarefree numbers
1083+
// https://oeis.org/A005117
1084+
// https://oeis.org/wiki/Squarefree_numbers
1085+
// 密度(见后面 calcMu 的注释)为 6/Pi^2 ≈ 0.6079
1086+
initSquarefreeNumbers := func() []int {
1087+
const mx int = 1e6
1088+
free := make([]bool, mx+1)
1089+
for i := 1; i <= mx; i++ {
1090+
free[i] = true
1091+
}
1092+
for i := 2; i*i <= mx; i++ {
1093+
for j := 1; i*i*j <= mx; j++ {
1094+
free[i*i*j] = false
1095+
}
1096+
}
1097+
// 注意特判 1
1098+
sf := []int{}
1099+
for i, f := range free {
1100+
if f {
1101+
sf = append(sf, i)
1102+
}
1103+
}
1104+
return sf
1105+
}
1106+
10821107
// LPF(n): least prime dividing n (when n > 1); a(1) = 1 https://oeis.org/A020639
10831108
// 有时候数据范围比较大,用 primeFactorsAll 预处理会 MLE,这时候就要用 LPF 了(同样是预处理但是内存占用低)
10841109
// 先预处理出 LPF,然后对要处理的数 v 不断地除 LPF(v) 直到等于 1
@@ -1975,6 +2000,7 @@ func numberTheoryCollection() {
19752000
// 所有在 n×n 格点中不越过对角线的单调路径的个数
19762001
// Number of noncrossing partitions of the n-set (不相交握手问题) LC1259/双周赛13D https://leetcode-cn.com/contest/biweekly-contest-13/problems/handshakes-that-dont-cross/
19772002
// Dyck Path https://mathworld.wolfram.com/DyckPath.html
2003+
// https://www.luogu.com.cn/problem/P1641
19782004
//
19792005
// 将全部偶数提取一个 2,可得 (2n)! = 1*3*5*...*(2n-1) * (2^n) * (n!)
19802006
// 故 C(2*n,n)/(n+1) = (2*n)!/(n!)/(n+1)! = 1*3*5*...*(2n-1)*(2^n)/(n+1)!
@@ -2557,7 +2583,7 @@ func numberTheoryCollection() {
25572583
sqCheck, cubeCheck, sqrt, cbrt, bottomDiff,
25582584
gcd, gcdPrefix, gcdSuffix, lcm, lcms, makeFrac, lessFrac, countDifferentSubsequenceGCDs, floorSum,
25592585
isPrime, sieve, sieveEuler, sieveEulerTemplate, factorize, primeDivisors, powerOfFactorialPrimeDivisor, primeExponentsCountAll, primeExponentsCount,
2560-
divisors, divisorPairs, doDivisors, doDivisors2, oddDivisorsNum, maxSqrtDivisor, divisorsAll, primeFactorsAll, lpfAll, distinctPrimesCountAll,
2586+
divisors, divisorPairs, doDivisors, doDivisors2, oddDivisorsNum, maxSqrtDivisor, divisorsAll, primeFactorsAll, lpfAll, initSquarefreeNumbers, distinctPrimesCountAll,
25612587
calcPhi, initPhi, sievePhi, exPhi,
25622588
primitiveRoot, primitiveRootsAll,
25632589
exgcd, solveLinearDiophantineEquations, invM, invP, divM, divP, initAllInv, calcAllInv,
@@ -2583,6 +2609,7 @@ https://codeforces.com/problemset/problem/300/C
25832609
https://codeforces.com/problemset/problem/520/E
25842610
https://codeforces.com/problemset/problem/559/C
25852611
https://codeforces.com/problemset/problem/869/C
2612+
https://codeforces.com/problemset/problem/1204/E 推荐
25862613
https://codeforces.com/problemset/problem/1261/D2 推荐
25872614
https://codeforces.com/problemset/problem/1288/C
25882615
https://codeforces.com/problemset/problem/1342/E

copypasta/math_ntt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ http://blog.miskcoo.com/2015/05/polynomial-multipoint-eval-and-interpolation
3535
关于优化形式幂级数计算的 Newton 法的常数 http://negiizhao.blog.uoj.ac/blog/4671
3636
3737
从拉插到快速插值求值 https://www.luogu.com.cn/blog/command-block/zong-la-cha-dao-kuai-su-cha-zhi-qiu-zhi
38+
浅谈多项式复合和拉格朗日反演 https://www.luogu.com.cn/blog/your-alpha1022/qian-tan-duo-xiang-shi-fu-ge-hu-la-ge-lang-ri-fan-yan
3839
快速阶乘算法 https://www.luogu.com.cn/problem/P5282
3940
调和级数求和 https://www.luogu.com.cn/problem/P5702
4041

copypasta/rand.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
https://oi-wiki.org/misc/rand-technique/
1111
1212
https://codeforces.com/problemset/problem/995/C
13+
https://codeforces.com/problemset/problem/1314/D 推荐
1314
https://codeforces.com/problemset/problem/1523/D
1415
https://codingcompetitions.withgoogle.com/kickstart/round/0000000000435c44/00000000007ec290
1516
*/

copypasta/segment_tree.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package copypasta
1919
// 取模 https://codeforces.com/problemset/problem/438/D
2020
// 转换的好题 https://codeforces.com/problemset/problem/1187/D
2121
// 合并 https://codeforces.com/problemset/problem/380/C
22+
// k 维曼哈顿(单点修改+区间最大值)https://codeforces.com/problemset/problem/1093/G
2223
// 区间 mex https://blog.csdn.net/includelhc/article/details/79593496
2324
// 反向构造题 https://www.luogu.com.cn/problem/P6852
2425
// 区间(绝对)众数及其次数(摩尔投票算法)https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
@@ -495,6 +496,7 @@ func (o *stNode) merge(b *stNode) *stNode {
495496

496497
// EXTRA: 线段树分裂
497498
// 将区间 [l,r] 从 o 中分离到 b 上
499+
// https://www.luogu.com.cn/blog/cyffff/talk-about-segument-trees-split
498500
// https://www.luogu.com.cn/problem/P5494
499501
// rt, rt2 := rt.split(nil, l, r)
500502
func (o *stNode) split(b *stNode, l, r int) (*stNode, *stNode) {
@@ -540,6 +542,7 @@ func (o *stNode) kth(k int64) int {
540542
// 模板题 https://www.luogu.com.cn/problem/P3919
541543
// https://www.luogu.com.cn/problem/P3834 https://www.acwing.com/problem/content/257/ https://ac.nowcoder.com/acm/contest/7613/C
542544
// 二分,转换成找最长的已填入数字的区间,做法类似最大子段和 https://codeforces.com/problemset/problem/484/E
545+
// 与 DFS序+深度 结合 https://codeforces.com/problemset/problem/893/F
543546
// todo 种类数 https://codeforces.com/problemset/problem/620/E
544547
// https://codeforces.com/problemset/problem/786/C
545548
// 差分 https://codeforces.com/problemset/problem/813/E

0 commit comments

Comments
 (0)