Skip to content

Commit

Permalink
add links
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessCheng committed May 12, 2023
1 parent 0b43344 commit dfce578
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 8 deletions.
3 changes: 3 additions & 0 deletions copypasta/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ https://codeforces.com/problemset/problem/1608/C 对拍找反例
构造
LC767 https://leetcode.cn/problems/reorganize-string/
LC667 https://leetcode.cn/problems/beautiful-arrangement-ii/
1500 https://codeforces.com/problemset/problem/1809/C
https://atcoder.jp/contests/arc145/tasks/arc145_a
+贪心 https://codeforces.com/problemset/problem/118/C
+分类讨论 https://codeforces.com/problemset/problem/584/C
Expand Down Expand Up @@ -135,6 +136,7 @@ https://codeforces.com/problemset/problem/796/C
https://codeforces.com/problemset/problem/1594/F
https://codeforces.com/problemset/problem/1798/E
https://codeforces.com/problemset/problem/1811/F
https://codeforces.com/problemset/problem/1714/F 锻炼代码实现技巧的好题
大量分类讨论
https://codeforces.com/problemset/problem/356/C
Expand All @@ -146,6 +148,7 @@ https://codeforces.com/problemset/problem/912/D
https://codeforces.com/problemset/problem/915/F
https://codeforces.com/problemset/problem/1208/E
https://codeforces.com/problemset/problem/1777/D 树
https://codeforces.com/problemset/problem/1788/D 好题!
https://codeforces.com/problemset/problem/1808/D
其他
Expand Down
42 changes: 41 additions & 1 deletion copypasta/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ GP: Sn = a1*(q^n-1)/(q-1), q!=1
∑^∞ r^i = 1/(1-r)
∑^∞ i*r^i = r/(1-r)^2
处理绝对值·曼哈顿距离转切比雪夫距离
每个点 (x,y) 改成 (x+y,x-y)
|x1-x2|+|y1-y2| 就可以用 max(|x1'-x2'|,|y1'-y2'|) 来计算了
https://codeforces.com/problemset/problem/1689/D
LC1131 https://leetcode.cn/problems/maximum-of-absolute-value-expression/
处理绝对值·分类讨论
https://leetcode.cn/problems/reverse-subarray-to-maximize-array-value/solution/bu-hui-hua-jian-qing-kan-zhe-pythonjavac-c2s6/
勾股数 https://oeis.org/A008846
斜边 https://oeis.org/A004613 Numbers that are divisible only by primes congruent to 1 mod 4
https://en.wikipedia.org/wiki/Pythagorean_triple https://zh.wikipedia.org/wiki/%E5%8B%BE%E8%82%A1%E6%95%B0
Expand Down Expand Up @@ -1102,6 +1111,28 @@ func _(abs func(int64) int64, max func(int64, int64) int64) {
return
}

// 无需额外空间的写法
// https://leetcode.cn/problems/smallest-integer-divisible-by-k/solution/san-chong-suan-fa-you-hua-pythonjavacgo-tk4cj/
divisorsO1Space := func(n int64) {
// 从小到大枚举不超过 sqrt(n) 的因子
i := int64(1)
for ; i*i <= n; i++ {
if n%i == 0 {
// do i ...
}
}
// 从小到大枚举大于 sqrt(n) 的因子
i--
if i*i == n {
i-- // 避免重复统计
}
for ; i > 0; i-- {
if n%i == 0 {
// do m/i ...
}
}
}

// Number of odd divisors of n https://oeis.org/A001227
// a(n) = d(2*n) - d(n)
// 亦为整数 n 分拆成若干连续整数的方法数
Expand Down Expand Up @@ -1710,6 +1741,13 @@ func _(abs func(int64) int64, max func(int64, int64) int64) {
}
}

// 欧拉定理
// 如果 gcd(a,n) = 1,则 a^φ(n) ≡ 1(mod n)
// 推论:如果 gcd(a,n) = 1,则 a^x ≡ 1(mod n) 的最小正整数解是 φ(n) 的因子(证明见《算法竞赛进阶指南》)
// LC1015 https://leetcode.cn/problems/smallest-integer-divisible-by-k/ http://poj.org/problem?id=3696
// https://atcoder.jp/contests/abc222/tasks/abc222_g
// https://oj.socoding.cn/p/1981

// 扩展欧拉定理(降幂公式)
// https://oi-wiki.org/math/fermat/#_5
// https://zhuanlan.zhihu.com/p/42632291
Expand Down Expand Up @@ -2037,7 +2075,9 @@ func _(abs func(int64) int64, max func(int64, int64) int64) {
// todo https://www.luogu.com.cn/blog/command-block/yuan-gen-li-san-dui-shuo-xiang-guan
// http://blog.miskcoo.com/2015/05/discrete-logarithm-problem
// https://www.luogu.com.cn/blog/hzoiliuchang/shuo-lun-zhi-bsgs-suan-fa
//
// 模板题 https://www.luogu.com.cn/problem/P3846
// https://atcoder.jp/contests/abc222/tasks/abc222_g
// todo https://atcoder.jp/contests/abc270/tasks/abc270_g
babyStepGiantStep := func(a, b, p, k int64) int64 { // 非 exBSGS 下 k=1
b %= p
Expand Down Expand Up @@ -2933,7 +2973,7 @@ func _(abs func(int64) int64, max func(int64, int64) int64) {
sqCheck, cubeCheck, sqrt, cbrt, bottomDiff,
gcd, gcdPrefix, gcdSuffix, lcm, lcms, makeFrac, lessFrac, countDifferentSubsequenceGCDs, floorSum,
isPrime, sieve, sieveEuler, sieveEulerTemplate, factorize, primeDivisors, primeDivisors2, powerOfFactorialPrimeDivisor, primeExponentsCountAll, primeExponentsCount,
divisors, oddDivisorsNum, maxSqrtDivisor, divisorsAll, primeFactorsAll, lpfAll, initSquarefreeNumbers, distinctPrimesCountAll,
divisors, divisorsO1Space, oddDivisorsNum, maxSqrtDivisor, divisorsAll, primeFactorsAll, lpfAll, initSquarefreeNumbers, distinctPrimesCountAll,
calcPhi, initPhi, sievePhi, exPhi,
primitiveRoot, primitiveRootsAll,
exgcd, solveLinearDiophantineEquations, invM, invP, divM, divP, calcAllInv,
Expand Down
2 changes: 1 addition & 1 deletion copypasta/math_fwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func fwt(a, b []int, fwtFunc func([]int, int) []int, invOp int) []int {
// 注:若代码性能瓶颈在 FWT 上,可以通过以下方式消除比较慢的乘法和取模(CF 上需要将 int64 改成 int)
// 优化前 1575ms https://codeforces.com/contest/1218/submission/118700754
// 优化后 748ms https://codeforces.com/contest/1218/submission/118704484
const _mod = 1e9 + 7
const _mod = 1_000_000_007

func add(a, b int) int {
a += b
Expand Down
3 changes: 3 additions & 0 deletions copypasta/math_ntt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ P-1 包含大量因子 2,便于分治
任意模数 NTT https://www.luogu.com.cn/problem/P4245
NTT vs FFT:对于模板题 https://www.luogu.com.cn/problem/P3803 NTT=1.98s(750ms) FFT=3.63s(1.36s) 括号内是最后一个 case 的运行时间
卡常技巧
A modulo multiplication method that is 2x faster than compiler implementation https://codeforces.com/blog/entry/111566
*/

/* 多项式全家桶
Expand Down
2 changes: 1 addition & 1 deletion copypasta/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func miscCollection() {
}

// 01 矩阵,每个 1 位置向四个方向延伸连续 1 的最远距离
// https://codingcompetitions.withgoogle.com/kickstart/round/0000000000436140/000000000068c509
// Kick Start 2021 Round A L Shaped Plots https://codingcompetitions.withgoogle.com/kickstart/round/0000000000436140/000000000068c509
max1dir4 := func(a [][]int) (ls, rs, us, ds [][]int) {
n, m := len(a), len(a[0])
ls, rs = make([][]int, n), make([][]int, n)
Expand Down
1 change: 1 addition & 0 deletions copypasta/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ https://codeforces.com/problemset/problem/995/C
https://codeforces.com/problemset/problem/1314/D 推荐
https://codeforces.com/problemset/problem/1523/D
Kick Start 2021 Round C Binary Operator https://codingcompetitions.withgoogle.com/kickstart/round/0000000000435c44/00000000007ec290
https://codeforces.com/problemset/problem/1689/D https://www.luogu.com.cn/blog/wangxiwen/solution-cf1689d
*/

/* 模拟退火 (Simulated Annealing, SA)
Expand Down
2 changes: 1 addition & 1 deletion copypasta/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func _(min, max func(int, int) int) {
// 我的视频讲解 https://www.bilibili.com/video/BV1na41137jv?t=15m43s
// https://en.wikipedia.org/wiki/Combinatorial_number_system#Applications
// 比如在 n 个数中求满足某种性质的最大子集,则可以从 n 开始倒着枚举子集大小,直到找到一个符合性质的子集
// 例题(TS1)https://codingcompetitions.withgoogle.com/codejam/round/0000000000007706/0000000000045875
// 例题(TS1)GCJ 2018 R2 Costume Change https://codingcompetitions.withgoogle.com/codejam/round/0000000000007706/0000000000045875
loopSubsetK := func(a []int, k int) {
n := len(a)
for sub := 1<<k - 1; sub < 1<<n; {
Expand Down
3 changes: 3 additions & 0 deletions copypasta/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ sort.Ints 性能测试 https://codeforces.com/contest/977/submission/75301978
- [1898. 可移除字符的最大数目](https://leetcode.cn/problems/maximum-number-of-removable-characters/)
- [778. 水位上升的泳池中游泳](https://leetcode.cn/problems/swim-in-rising-water/)
- [2258. 逃离火灾](https://leetcode.cn/problems/escape-the-spreading-fire/)
https://codeforces.com/problemset/problem/1118/D2
DP https://codeforces.com/contest/883/problem/I
#### 最小化最大值
- [2439. 最小化数组中的最大值](https://leetcode.cn/problems/minimize-maximum-of-array/)
Expand Down Expand Up @@ -66,6 +68,7 @@ https://codeforces.com/problemset/problem/1201/C 也可以贪心做
1759 http://poj.org/problem?id=1759 递推式变形成差分,这样可以二分 B,判断最小值是否非负
3484 https://www.acwing.com/problem/content/122/ 二分位置
https://codeforces.com/problemset/problem/1697/D
隐藏的二分 https://atcoder.jp/contests/abc203/tasks/abc203_d
隐藏的二分 https://codeforces.com/problemset/problem/1354/D
转换的好题 https://codeforces.com/problemset/problem/1181/D
Expand Down
4 changes: 4 additions & 0 deletions copypasta/sqrt_decomposition.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ https://codeforces.com/problemset/problem/1039/E
大步+小步,有点分段打表的味道 https://codeforces.com/problemset/problem/1619/H
https://codeforces.com/problemset/problem/1806/E
见下面的 floorDivide https://codeforces.com/problemset/problem/786/C
自动 O(n√n)
https://codeforces.com/problemset/problem/1790/F
*/

// TIPS: n 的整数分拆中,不同数字的个数至多有 O(√n) 种
Expand All @@ -49,6 +52,7 @@ https://www.luogu.com.cn/problem/P6466
分块数据结构
https://oi-wiki.org/ds/decompose/
https://oi-wiki.org/ds/block-array/
Unrolled linked list https://en.wikipedia.org/wiki/Unrolled_linked_list
【推荐】https://www.luogu.com.cn/blog/220037/Sqrt1
浅谈基础根号算法——分块 https://www.luogu.com.cn/blog/deco/qian-tan-ji-chu-gen-hao-suan-fa-fen-kuai
todo https://www.csie.ntu.edu.tw/~sprout/algo2018/ppt_pdf/root_methods.pdf
Expand Down
11 changes: 7 additions & 4 deletions copypasta/union_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ https://zhuanlan.zhihu.com/p/553192435
// 基础题 https://codeforces.com/problemset/problem/1411/C
// LC305 https://leetcode.cn/problems/number-of-islands-ii/
// LC1562 https://leetcode.cn/problems/find-latest-group-of-size-m/
// 处理图上的环
// - https://codeforces.com/contest/1726/problem/D
// 数组标记/区间合并相关
// - [1851. 包含每个查询的最小区间](https://leetcode.cn/problems/minimum-interval-to-include-each-query/)
// - [2382. 删除操作后的最大子段和](https://leetcode.cn/problems/maximum-segment-sum-after-removals/)
Expand Down Expand Up @@ -54,7 +56,7 @@ https://zhuanlan.zhihu.com/p/553192435
// 分组排序套路 LC1998 https://leetcode-cn.com/problems/gcd-sort-of-an-array/
// 套题 https://blog.csdn.net/weixin_43914593/article/details/104108049 算法竞赛专题解析(3):并查集
// 转换 https://codeforces.com/problemset/problem/1253/D
// 离散 + 四方向 https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050ff2/0000000000150aac#analysis
// 离散 + 四方向 Kick Start 2019 Round C Wiggle Walk https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050ff2/0000000000150aac#analysis
// 技巧:去掉无用数据
// - https://codeforces.com/problemset/problem/1157/E
// - https://codeforces.com/problemset/problem/1791/F
Expand Down Expand Up @@ -254,7 +256,7 @@ func moveRobot(start ufPoint, command string) ufPoint {
return p
}

// 并查集 - 维护点权
// 点权并查集
// 维护的可以是集合的大小、最值、XOR、GCD 等
// https://codeforces.com/edu/course/2/lesson/7/1/practice/contest/289390/problem/B
// https://codeforces.com/problemset/problem/1609/D
Expand Down Expand Up @@ -298,7 +300,7 @@ func _(n int) {
_ = []interface{}{merge, same, size}
}

// 并查集 - 维护边权(种类
// 边权并查集(种类并查集
// 核心在于:
// 2 ------ 4
// / /
Expand All @@ -321,6 +323,7 @@ func _(n int) {
// https://codeforces.com/contest/1713/problem/E
// 边权:https://codeforces.com/edu/course/2/lesson/7/1/practice/contest/289390/problem/C
// 边权:LC399 除法求值 https://leetcode.cn/problems/evaluate-division/
// https://codeforces.com/problemset/problem/1788/F
func _(n int) {
// 注:kinds 为 2 时可以用异或来代替加减法
const kinds = 2
Expand All @@ -333,7 +336,7 @@ func _(n int) {
find = func(x int) int {
if fa[x] != x {
ffx := find(fa[x])
dis[x] += dis[fa[x]]
dis[x] += dis[fa[x]] //
fa[x] = ffx
}
return fa[x]
Expand Down

0 comments on commit dfce578

Please sign in to comment.