Skip to content

Commit 4cb51ef

Browse files
committed
add links
1 parent 8cbc960 commit 4cb51ef

30 files changed

+349
-167
lines changed

copypasta/bits.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Precedence Operator
5555
两数 OR 的最小值:只需要知道区间内最小的 bits.Len(U) + 1 个数 https://codeforces.com/problemset/problem/1665/E
5656
连续数字 AND 等于目标值 https://codeforces.com/problemset/problem/1775/C 1600
5757
https://codeforces.com/problemset/problem/1004/F 2600
58+
https://codeforces.com/problemset/problem/1945/H 2600 分类暴力
5859
5960
### 异或(XOR)的性质
6061
另见 strings.go 中的 trie.maxXor
@@ -133,21 +134,24 @@ popcount(a&b) + popcount(a|b) = popcount(a) + popcount(b)
133134
- [2354. 优质数对的数目](https://leetcode.cn/problems/number-of-excellent-pairs/) 2076
134135
https://oeis.org/A006234 (n+2) * 3^(n-2) [0,2^n) 内任意两数 popcount(x) + popcount(y) - popcount(x+y) = 1 的数对个数
135136
- https://codeforces.com/problemset/problem/1761/D
136-
进位与分类讨论 https://codeforces.com/problemset/problem/1761/D https://www.luogu.com.cn/blog/linyihdfj/solution-cf1761d https://www.cnblogs.com/linyihdfj/p/16893607.html
137+
进位与分类讨论 https://codeforces.com/problemset/problem/1761/D 2100
138+
- https://www.luogu.com.cn/blog/linyihdfj/solution-cf1761d
139+
- https://www.cnblogs.com/linyihdfj/p/16893607.html
137140
a|b = (a^b) + (a&b)
138141
a&b = (a|b) - (a^b)
139142
a^b = (a|b) - (a&b)
140143
a+b = (a|b) + (a&b)
141144
= (a&b)*2 + (a^b)
142145
= (a|b)*2 - (a^b)
143146
(a^b) & (a&b) = 0 恒成立
144-
https://codeforces.com/problemset/problem/76/D
145-
https://codeforces.com/problemset/problem/1325/D
146-
https://codeforces.com/problemset/problem/1368/D
147-
https://codeforces.com/problemset/problem/1790/E
147+
https://codeforces.com/problemset/problem/1790/E 1400
148+
https://codeforces.com/problemset/problem/76/D 1700
149+
https://codeforces.com/problemset/problem/627/A 1700
150+
https://codeforces.com/problemset/problem/1325/D 1700
151+
https://codeforces.com/problemset/problem/1368/D 1700
148152
https://atcoder.jp/contests/abc050/tasks/arc066_b
149153
a|b = (^a)&b + a
150-
+ 与 ^ https://codeforces.com/problemset/problem/1732/C2
154+
+ 与 ^ https://codeforces.com/problemset/problem/1732/C2 2100
151155
进位的本质 https://atcoder.jp/contests/arc158/tasks/arc158_c
152156
max(a,b) = (a + b + abs(a-b)) / 2
153157
min(a,b) = (a + b - abs(a-b)) / 2

copypasta/common.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ https://codeforces.com/problemset/problem/466/C
8888
- [2489. 固定比率的子字符串数](https://leetcode.cn/problems/number-of-substrings-with-fixed-ratio/)(会员题)
8989
https://atcoder.jp/contests/abc233/tasks/abc233_d
9090
交错前缀和 https://codeforces.com/contest/1915/problem/E
91+
http://codeforces.com/problemset/problem/1446/D1 2600 转换
9192
9293
前缀和思想 LC1523 https://leetcode.cn/problems/count-odd-numbers-in-an-interval-range/
9394
有点数形结合 https://codeforces.com/problemset/problem/1748/C
@@ -144,6 +145,7 @@ https://codeforces.com/problemset/problem/1296/C
144145
- [487. 最大连续 1 的个数 II](https://leetcode.cn/problems/max-consecutive-ones-ii/)(会员题)
145146
- [1746. 经过一次操作后的最大子数组和](https://leetcode.cn/problems/maximum-subarray-sum-after-one-operation/)(会员题)
146147
https://codeforces.com/problemset/problem/1178/B 1300
148+
https://codeforces.com/problemset/problem/1443/B 1300
147149
https://codeforces.com/problemset/problem/1706/C 1400
148150
https://codeforces.com/problemset/problem/1837/F 2400
149151
@@ -271,6 +273,7 @@ https://atcoder.jp/contests/abc155/tasks/abc155_d
271273
272274
a[i] + b[j] = target 的方案数
273275
a[i] + b[j] < target 的方案数 相向双指针 https://leetcode.cn/problems/count-pairs-whose-sum-is-less-than-target/
276+
https://codeforces.com/problemset/problem/1538/C 1300
274277
a[i] + b[j] > target 的方案数 同上
275278
a[i] - b[j] = target 的方案数
276279
a[i] - b[j] < target 的方案数 滑窗
@@ -351,6 +354,7 @@ https://codeforces.com/problemset/problem/846/C
351354
- [3088. 使字符串反回文](https://leetcode.cn/problems/make-string-anti-palindrome/)(会员题)
352355
https://codeforces.com/problemset/problem/1920/B 1100
353356
https://codeforces.com/problemset/problem/545/D 1300
357+
https://codeforces.com/problemset/problem/1443/B 1300
354358
https://codeforces.com/problemset/problem/388/A 1400
355359
https://codeforces.com/problemset/problem/1443/C 1400
356360
https://codeforces.com/problemset/problem/864/D 1500
@@ -411,6 +415,7 @@ https://codeforces.com/problemset/problem/934/A 1400
411415
- [LCP 24. 数字游戏](https://leetcode.cn/problems/5TxKeK/)
412416
- [296. 最佳的碰头地点](https://leetcode.cn/problems/best-meeting-point/) 二维的情况(会员题)
413417
https://codeforces.com/problemset/problem/710/B 1400
418+
中位数相关 https://codeforces.com/problemset/problem/166/C 1500 *可以做到对不同的 x 用 O(log n) 时间回答
414419
415420
### 排序不等式
416421
- [2285. 道路的最大总重要性](https://leetcode.cn/problems/maximum-total-importance-of-roads/) 1496
@@ -471,7 +476,8 @@ LC280 https://leetcode.cn/problems/wiggle-sort/
471476
LC3012 https://leetcode.cn/problems/minimize-length-of-array-using-operations/
472477
https://codeforces.com/problemset/problem/1009/B 1400
473478
https://codeforces.com/problemset/problem/1169/B 1500
474-
https://codeforces.com/problemset/problem/500/C 1600
479+
https://codeforces.com/problemset/problem/500/C 1600
480+
https://codeforces.com/problemset/problem/601/A 1600
475481
https://codeforces.com/problemset/problem/1763/C 2000
476482
https://atcoder.jp/contests/abc194/tasks/abc194_e
477483
https://atcoder.jp/contests/abc196/tasks/abc196_e
@@ -1097,7 +1103,8 @@ func _() {
10971103
return sum
10981104
}
10991105

1100-
// 前缀和应用:求距离和
1106+
// 前缀和
1107+
// LC303 https://leetcode.cn/problems/range-sum-query-immutable/
11011108
prefixSum := func(a []int) {
11021109
slices.Sort(a)
11031110
sum := make([]int, len(a)+1)

copypasta/cp.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package copypasta
2+
3+
/*
4+
Competitive Programming Roadmap (target: [gray, blue]) https://codeforces.com/blog/entry/111099
5+
A way to Practice Competitive Programming : From Rating 1000 to 2400+ https://codeforces.com/blog/entry/66909
6+
https://cin.ufpe.br/~fbma/Crack/%5BTutorial%5D%20A%20Way%20to%20Practice%20Competitive%20Programming.pdf
7+
8+
解决问题的一般方法 https://codeforces.com/blog/entry/92248?#comment-809401
9+
General ideas https://codeforces.com/blog/entry/48417
10+
从特殊到一般:尝试修改条件或缩小题目的数据范围,先研究某个特殊情况下的思路,然后再逐渐扩大数据范围来思考怎么改进算法
11+
https://codeforces.com/blog/entry/126310
12+
13+
从特殊到一般
14+
https://codeforces.com/contest/1907/problem/C
15+
*/

copypasta/fenwick_tree.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/FenwickTree.java.html
2121
- https://www.luogu.com.cn/problem/P3374
2222
- [315. 计算右侧小于当前元素的个数](https://leetcode.cn/problems/count-of-smaller-numbers-after-self/) *逆序对
2323
- [2426. 满足不等式的数对数目](https://leetcode.cn/problems/number-of-pairs-satisfying-inequality/) 2030
24+
- [3072. 将元素分配到两个数组中 II](https://leetcode.cn/problems/distribute-elements-into-two-arrays-ii/)
2425
- [493. 翻转对](https://leetcode.cn/problems/reverse-pairs/)
2526
- [327. 区间和的个数](https://leetcode.cn/problems/count-of-range-sum/)
27+
- [2519. 统计 K-Big 索引的数量](https://leetcode.cn/problems/count-the-number-of-k-big-indices/)(会员题)
28+
- [2613. 美数对](https://leetcode.cn/problems/beautiful-pairs/)(会员题)*曼哈顿最近点对
2629
2730
关于逆序对,见下面的 cntInversions
2831
32+
https://codeforces.com/problemset/problem/1234/D 1600
2933
https://leetcode.cn/problems/shu-zu-zhong-de-ni-xu-dui-lcof/
3034
https://atcoder.jp/contests/arc075/tasks/arc075_c
3135
静态区间种类 - 离线做法
@@ -516,7 +520,7 @@ func _(n int) {
516520
// 树状数组维护前缀最小值的条件是每次修改只能往小改,那么从后往前做就好了
517521
// 将询问离线:按照右端点排序(或分组),计算 mex。原理见代码中 query 的注释
518522
// https://www.luogu.com.cn/problem/P4137
519-
// LC2003 https://leetcode-cn.com/problems/smallest-missing-genetic-value-in-each-subtree/
523+
// LC2003 https://leetcode.cn/problems/smallest-missing-genetic-value-in-each-subtree/
520524
// - 需要将 a 转换成 DFS 序且从 0 开始,同时最终答案需要 +1
521525
func rangeMex(a []int, qs []struct{ l, r, i int }) []int {
522526
const mx int = 1e5 + 2

copypasta/games.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ https://en.wikipedia.org/wiki/Mex_(mathematics)
2929
入门分类讨论 https://codeforces.com/problemset/problem/78/C
3030
三定理的模板题 https://codeforces.com/problemset/problem/1033/C
3131
https://atcoder.jp/contests/dp/tasks/dp_k
32+
LC2868 https://leetcode.cn/problems/the-wording-game/
3233
1-2-K Game https://codeforces.com/problemset/problem/1194/D 我的题解 https://www.acwing.com/file_system/file/content/whole/index/content/3179098/
3334
TODO: 题目推荐 https://blog.csdn.net/ACM_cxlove/article/details/7854526
3435
一道不错的有向图博弈 https://codeforces.com/problemset/problem/936/B
@@ -37,49 +38,56 @@ todo 威佐夫博弈 https://www.luogu.com.cn/problem/P2252
3738
todo 阶梯博弈 移动金币 https://www.luogu.com.cn/problem/P5363
3839
todo poj 2484 2348 1704 2311 | 1082 2068 3688 1740 2975 3537 2315
3940
todo https://codeforces.com/problemset/problem/138/D (注:这是挑战上推荐的题目)
40-
对于有环图的博弈,可以从终点(确定的状态)来倒推 https://leetcode-cn.com/problems/cat-and-mouse-ii/solution/mao-he-lao-shu-ii-bu-xu-yao-xian-zhi-bu-d2yxn/
41+
对于有环图的博弈,可以从终点(确定的状态)来倒推 https://leetcode.cn/problems/cat-and-mouse-ii/solution/mao-he-lao-shu-ii-bu-xu-yao-xian-zhi-bu-d2yxn/
4142
通过必败态去筛必胜态 https://ac.nowcoder.com/acm/contest/11166/A
42-
两端取数问题 https://atcoder.jp/contests/dp/tasks/dp_l LC486 https://leetcode-cn.com/problems/predict-the-winner/ LC877 https://leetcode-cn.com/problems/stone-game/
43+
两端取数问题 https://atcoder.jp/contests/dp/tasks/dp_l
44+
- LC486 https://leetcode.cn/problems/predict-the-winner/
45+
- LC877 https://leetcode.cn/problems/stone-game/
46+
todo 交互+博弈 https://codeforces.com/problemset/problem/1903/E
4347
*/
4448
func _() {
4549
{
4650
// 基础打表
4751
p, q := 3, 4
4852

53+
// 如果两个人的规则一样,则可以去掉 who
54+
// 例题 https://www.lanqiao.cn/problems/8051/learning/?contest_id=146
4955
const mx int = 100
50-
win := [mx + 1][2]int{} // -1 表示败;1 表示胜
51-
var f func(int, int) int
52-
f = func(n, who int) (res int) { // 0 为先手;1 为后手
56+
dp := make([][2]int8, mx+1) // -1 表示败;1 表示胜
57+
var f func(int, uint8) int8
58+
f = func(i int, who uint8) (res int8) { // 0 为先手;1 为后手
5359
// 无法操作的情况
54-
if n == 0 {
60+
if i == 0 {
5561
return -1
5662
}
5763
if who == 0 {
5864
// 检查边界
59-
if n <= p {
65+
if i <= p {
6066
return 1
6167
}
6268
} else {
6369
// 检查边界
64-
if n <= q {
70+
if i <= q {
6571
return 1
6672
}
6773
}
68-
dv := &win[n][who]
74+
75+
dv := &dp[i][who]
6976
if *dv != 0 {
7077
return *dv
7178
}
7279
defer func() { *dv = res }()
80+
7381
// 检查是否可以转移到必败态
7482
if who == 0 {
75-
for i := 1; i <= p; i++ {
76-
if f(n-i, who^1) == -1 {
83+
for j := 1; j <= p; j++ {
84+
if f(i-j, who^1) == -1 {
7785
return 1
7886
}
7987
}
8088
} else {
81-
for i := 1; i <= q; i++ {
82-
if f(n-i, who^1) == -1 {
89+
for j := 1; j <= q; j++ {
90+
if f(i-j, who^1) == -1 {
8391
return 1
8492
}
8593
}
@@ -117,6 +125,7 @@ func _() {
117125
// 异或和不为零则先手必胜
118126
// https://blog.csdn.net/weixin_44023181/article/details/85619512
119127
// 模板题 https://www.luogu.com.cn/problem/P2197
128+
// - [1908. Nim 游戏 II](https://leetcode.cn/problems/game-of-nim/)(会员题)
120129
nim := func(a []int) (firstWin bool) {
121130
sum := 0
122131
for _, v := range a {
@@ -144,6 +153,7 @@ func _() {
144153
// 只能取 2^i 个:SG(n) = n%3
145154
// 只能取 p^i 个(p 为奇素数):SG(n) = n%2
146155
//
156+
// - [2005. 斐波那契树的移除子树游戏](https://leetcode.cn/problems/subtree-removal-game-with-fibonacci-tree/)(会员题)
147157
// 整数分拆博弈 https://codeforces.com/problemset/problem/87/C
148158
// 取石子变形
149159
// - https://codeforces.com/problemset/problem/850/C

copypasta/geometry.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ A=i+b/2-1, A为多边形面积,i为内部格点数,b为边上格点数
9191
https://codeforces.com/problemset/problem/1548/D1
9292
https://codeforces.com/problemset/problem/1548/D2
9393
94+
曼哈顿最近点对
95+
LC2613 https://leetcode.cn/problems/beautiful-pairs/
96+
9497
TIPS: 旋转坐标,适用于基于曼哈顿距离的题目
9598
顺时针旋转 45° (x,y) -> (x+y,y-x) 记作 (x',y')
9699
曼哈顿距离 |x1-x2|+|y1-y2| = max(|x1'-x2'|,|y1'-y2'|)

copypasta/graph_tree.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ NOTE: 记录从 x 到根的路径上的每个点到 x 的距离,就可以从 y
2626
- [2368. 受限条件下可到达节点的数目](https://leetcode.cn/problems/reachable-nodes-with-restrictions/) 1477
2727
- [3004. 相同颜色的最大子树](https://leetcode.cn/problems/maximum-subtree-of-the-same-color/)(会员题)
2828
https://codeforces.com/problemset/problem/580/C
29+
https://codeforces.com/problemset/problem/34/D 1600
2930
3031
利用递归栈快速标记祖先节点 https://codeforces.com/problemset/problem/1774/E
3132
树上统计(从下往上)典型题 https://codeforces.com/problemset/problem/766/E
@@ -191,7 +192,7 @@ func (*tree) depthSize(n, root int, g [][]int, v int) {
191192
dep := make([]int, n)
192193
size := make([]int, n)
193194
maxDep := make([]int, n) // EXTRA: 子树最大深度
194-
var build func(v, fa, d int) int
195+
var build func(int, int, int) int
195196
build = func(v, fa, d int) int {
196197
dep[v] = d
197198
sz := 1
@@ -218,17 +219,19 @@ func (*tree) depthSize(n, root int, g [][]int, v int) {
218219
//
219220
// https://codeforces.com/problemset/problem/877/E 2000
220221
// https://codeforces.com/problemset/problem/383/C 2000
221-
// https://ac.nowcoder.com/acm/contest/6383/B
222+
// https://codeforces.com/problemset/problem/620/E 2100
222223
// https://codeforces.com/problemset/problem/916/E 2400
223-
// 结合 AC 自动机 https://codeforces.com/contest/163/problem/E 2800
224+
// https://codeforces.com/problemset/problem/1110/F 2600
225+
// https://codeforces.com/problemset/problem/163/E 2800 结合 AC 自动机
226+
// https://ac.nowcoder.com/acm/contest/6383/B
224227
func (*tree) subtreeSize(root int, g [][]int, a []int) {
225-
newOrder := make([]int, len(a))
228+
newOrder := make([]int, 0, len(a))
226229

227-
nodes := make([]struct{ l, r int }, len(g)) // 闭区间
230+
nodes := make([]struct{ l, r int }, len(g)) // 闭区间 [l,r]
228231
dfn := 0
229232
var buildDFN func(int, int) int
230233
buildDFN = func(v, fa int) (size int) {
231-
newOrder[dfn] = a[v] // 按照遍历顺序得到的点权顺序
234+
newOrder = append(newOrder, a[v]) // 按照遍历顺序得到的点权顺序
232235

233236
dfn++ // 相当于 dfn 从 1 开始
234237
nodes[v].l = dfn
@@ -1625,17 +1628,20 @@ func (*tree) virtualTree(g [][]int) {
16251628
// 树链剖分详解 https://www.cnblogs.com/zwfymqz/p/8094500.html
16261629
// 树链剖分详解 https://www.luogu.com.cn/blog/communist/shu-lian-pou-fen-yang-xie
16271630
//
1628-
// 注:若没有修改操作, lcaBinaryLifting(路径查询)以及 subtreeSize(子树查询)
1631+
// 注:若没有修改操作,更简单的做法见 lcaBinaryLifting(路径查询)以及 subtreeSize(子树查询)
16291632
//
16301633
// 模板题(点权)https://www.luogu.com.cn/problem/P3384
16311634
// https://codeforces.com/problemset/problem/343/D 2100
16321635
// 模板题(边权)https://atcoder.jp/contests/abc294/tasks/abc294_g
16331636
// 与最小生成树结合(边权)https://codeforces.com/problemset/problem/609/E
16341637
// 好题 https://codeforces.com/contest/1174/problem/F
16351638
// 归并树 https://codeforces.com/problemset/problem/587/C
1636-
// todo 子异和 https://www.luogu.com.cn/problem/P5127
1637-
// todo 完成题单 https://www.luogu.com.cn/training/1654
1639+
// todo 题单 https://www.luogu.com.cn/training/1654
1640+
// todo https://www.luogu.com.cn/problem/P5127
16381641
// TODO: 处理边权的情况
1642+
// https://www.luogu.com.cn/problem/P1505
1643+
// https://www.luogu.com.cn/problem/P4315
1644+
// https://www.luogu.com.cn/problem/P4114
16391645
// todo NOI21 轻重边 https://www.luogu.com.cn/problem/P7735
16401646
// https://www.luogu.com.cn/problem/P4211
16411647
// 结合广义圆方树 https://codeforces.com/problemset/problem/487/E

copypasta/implementation.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package copypasta
22

3-
/*
3+
/* 小模拟
4+
LC588 https://leetcode.cn/problems/design-in-memory-file-system/
5+
LC2534 https://leetcode.cn/problems/time-taken-to-cross-the-door/
6+
LC723 https://leetcode.cn/problems/candy-crush/(会员题)
7+
*/
8+
9+
/* 大模拟
410
题单
511
https://www.luogu.com.cn/training/3210#problems
612
https://www.luogu.com.cn/training/126320#problems

0 commit comments

Comments
 (0)