Skip to content

Commit e217f0e

Browse files
committed
add links
1 parent 5bb1fb8 commit e217f0e

11 files changed

+133
-99
lines changed

copypasta/geometry.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ https://en.wikipedia.org/wiki/Determinant#Geometric_meaning
5252
- b在a右侧
5353
0 ab平行或重合(共基线)
5454
关于有向面积 https://cp-algorithms.com/geometry/oriented-triangle-area.html
55+
https://codeforces.com/gym/105139/problem/B
5556
5657
1° = (π/180)rad
5758
1rad = (180/π)°
@@ -97,8 +98,9 @@ TIPS: 旋转坐标
9798
顺时针旋转 45° (x,y) -> (x+y,y-x) 记作 (x',y')
9899
曼哈顿距离转成切比雪夫距离(棋盘距离) |x1-x2|+|y1-y2| = max(|x1'-x2'|,|y1'-y2'|)
99100
模板题 https://atcoder.jp/contests/abc178/tasks/abc178_e
100-
https://leetcode.cn/problems/minimize-manhattan-distances/
101-
https://codeforces.com/problemset/problem/1689/D
101+
LC3102 https://leetcode.cn/problems/minimize-manhattan-distances/ 2216
102+
https://codeforces.com/problemset/problem/1689/D 1900
103+
https://codeforces.com/problemset/problem/1979/E 2400
102104
https://www.luogu.com.cn/problem/P5098
103105
todo LC1956 https://leetcode.cn/problems/minimum-time-for-k-virus-variants-to-spread/
104106
点到点集的最大曼哈顿距离 https://codeforces.com/problemset/problem/491/B

copypasta/heap.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ https://codeforces.com/problemset/problem/1196/F 2200
3434
#### 懒删除
3535
本页面搜索【懒删除堆】
3636
37-
#### 模拟
37+
#### 模拟
3838
- [2532. 过桥的时间](https://leetcode.cn/problems/time-to-cross-a-bridge/) 2589
39-
https://codeforces.com/contest/1945/problem/G
39+
https://codeforces.com/problemset/problem/1985/F
40+
https://codeforces.com/problemset/problem/1945/G 2500
4041
4142
#### 思维·转换
4243
- [2054. 两个最好的不重叠活动](https://leetcode.cn/problems/two-best-non-overlapping-events/) 1883
@@ -75,7 +76,7 @@ https://leetcode.cn/problems/minimum-time-to-complete-all-tasks/
7576
- [630. 课程表 III](https://leetcode.cn/problems/course-schedule-iii/)
7677
- JSOI07 建筑抢修 https://www.luogu.com.cn/problem/P4053
7778
- [871. 最低加油次数](https://leetcode.cn/problems/minimum-number-of-refueling-stops/) 2074
78-
- [2813. 子序列最大优雅度](https://leetcode.cn/problems/maximum-elegance-of-a-k-length-subsequence/) 2582
79+
- [2813. 子序列最大优雅度](https://leetcode.cn/problems/maximum-elegance-of-a-k-length-subsequence/) 2582 也可以用栈
7980
- [3049. 标记所有下标的最早秒数 II](https://leetcode.cn/problems/earliest-second-to-mark-indices-ii/) 3111
8081
- [2599. 使前缀和数组非负](https://leetcode.cn/problems/make-the-prefix-sum-non-negative/)(会员题)
8182
题单 https://www.luogu.com.cn/training/8793

copypasta/io.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111

1212
// bufio.NewWriter
1313
// 相比 fmt.Println,每减少 1e5 次 Flush 可以加速约 200ms(Codeforces/AtCoder)
14-
// 对比:
14+
// 也就是说,对于 1e4 及以下量级的输出,加不加 buffer 都一样,所以直接用 fmt.Println 输出即可
15+
// 注:大多数 CF 题目都是 T <= 1e4 的
16+
// 附对比:
1517
// 405ms https://codeforces.com/contest/1603/submission/135520593
1618
// 187ms https://codeforces.com/contest/1603/submission/134450945
1719
// NOTE: 调用 Fprintln 打印 int(0) 1e6 次的耗时为 77ms https://codeforces.com/contest/1603/submission/169796327

copypasta/math_basic.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ https://leetcode.cn/problems/harshad-number/
77
https://codeforces.com/problemset/problem/11/A 900 上取整
88
https://codeforces.com/problemset/problem/485/A 1400
99
https://codeforces.com/problemset/problem/1759/D 1400
10+
https://codeforces.com/problemset/problem/1950/F 1700
1011
*/

copypasta/math_fft.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ todo https://github.com/OI-wiki/gitment/discussions/670#discussioncomment-449602
3434
模板题 https://www.luogu.com.cn/problem/P3803
3535
todo 推式子 https://www.luogu.com.cn/problem/P3338 花絮 https://zhuanlan.zhihu.com/p/349249817
3636
todo https://codeforces.com/problemset/problem/993/E
37+
https://codeforces.com/gym/104081/problem/K
3738
*/
3839

3940
type fft struct {

copypasta/math_misc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ x = (b/a)*W((a/b)*e^(-c/b))
2121
LC2749 https://leetcode.cn/problems/minimum-operations-to-make-the-integer-zero/
2222
2323
一元五次方程的根 布灵根式 Bring radical https://en.wikipedia.org/wiki/Bring_radical
24+
25+
带余项的泰勒公式、欧拉-麦克劳林公式的推导 https://zhuanlan.zhihu.com/p/148221397
2426
*/

copypasta/misc.go

Lines changed: 88 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
小奥
2121
https://codeforces.com/problemset/problem/700/A
2222
23+
原地哈希
24+
LC442 https://leetcode.cn/problems/find-all-duplicates-in-an-array/
25+
2326
三维 n 皇后 https://oeis.org/A068940
2427
Maximal number of chess queens that can be placed on a 3-dimensional chessboard of order n so that no two queens attack each other
2528
@@ -899,83 +902,6 @@ func champernowneConstant(k int) int {
899902
}
900903
}
901904

902-
// 解析时间 力扣见过多次了
903-
func parseTime(s string) (hour, minute, total int) {
904-
hour = int(s[0]&15)*10 + int(s[1]&15)
905-
minute = int(s[3]&15)*10 + int(s[4]&15)
906-
total = hour*60 + minute
907-
return
908-
}
909-
910-
// 合并 a 中所有重叠的闭区间(哪怕只有一个端点重叠,也算重叠)
911-
// 注意 [1,1] 和 [2,2] 不能合并成 [1,2]
912-
// 注:这种做法在变形题中容易写错,更加稳定的做法是差分数组
913-
// - [56. 合并区间](https://leetcode.cn/problems/merge-intervals/)
914-
// - [55. 跳跃游戏](https://leetcode.cn/problems/jump-game/)
915-
// - [2580. 统计将重叠区间合并成组的方案数](https://leetcode.cn/problems/count-ways-to-group-overlapping-ranges/) 1632
916-
// - [2963. 统计好分割方案的数目](https://leetcode.cn/problems/count-the-number-of-good-partitions/) 1985
917-
// - [2584. 分割数组使乘积互质](https://leetcode.cn/problems/split-the-array-to-make-coprime-products/) 2159
918-
// - [2655. 寻找最大长度的未覆盖区间](https://leetcode.cn/problems/find-maximal-uncovered-ranges/)(会员题)
919-
// 另见 common.go 中的「区间贪心」
920-
// https://codeforces.com/problemset/problem/1626/C 1700
921-
// - 倒序合并代码 https://codeforces.com/contest/1626/submission/211306494
922-
// https://codeforces.com/problemset/problem/1859/D 1800
923-
// https://codeforces.com/problemset/problem/1260/D 1900
924-
func mergeIntervals(a [][]int) [][]int {
925-
slices.SortFunc(a, func(a, b []int) int { return a[0] - b[0] }) // 按区间左端点排序
926-
merged := [][]int{}
927-
l0 := a[0][0]
928-
maxR := a[0][1]
929-
for _, p := range a[1:] { // 从第二个区间开始
930-
l, r := p[0], p[1]
931-
// 如果要合并 [1,1] 和 [2,2],下面改成 if l-1 > maxR
932-
if l > maxR { // 发现一个新区间
933-
merged = append(merged, []int{l0, maxR}) // 先把旧的加入答案
934-
l0 = l // 记录新区间左端点
935-
}
936-
maxR = max(maxR, r)
937-
}
938-
merged = append(merged, []int{l0, maxR}) // 最后发现的新区间加入答案
939-
940-
{
941-
// 包含 x 的闭区间
942-
var x int
943-
i := sort.Search(len(merged), func(i int) bool { return merged[i][1] >= x })
944-
if i < len(merged) && merged[i][0] <= x {
945-
// ans[i]...
946-
}
947-
}
948-
949-
return merged
950-
}
951-
952-
// 从 i 可以跳到 [i,i+a[i]] 中的任意整点
953-
// 返回从 0 跳到 n-1 的最小跳跃次数
954-
// 如果无法到达 n-1,返回 -1
955-
// 注:对于复杂变形题,采用分组循环不易写错
956-
// - [45. 跳跃游戏 II](https://leetcode.cn/problems/jump-game-ii/)
957-
// - [1024. 视频拼接](https://leetcode.cn/problems/video-stitching/) 1746
958-
// - [1326. 灌溉花园的最少水龙头数目](https://leetcode.cn/problems/minimum-number-of-taps-to-open-to-water-a-garden/) 1885
959-
// 【图解】https://leetcode.cn/problems/minimum-number-of-taps-to-open-to-water-a-garden/solution/yi-zhang-tu-miao-dong-pythonjavacgo-by-e-wqry/
960-
// 变形 https://codeforces.com/contest/1630/problem/C
961-
func minJumpNumbers(a []int) (ans int) {
962-
curR := 0 // 已建造的桥的右端点
963-
nxtR := 0 // 下一座桥的右端点的最大值
964-
// 这里没有遍历到 n-1,因为它已经是终点了
965-
for i, d := range a[:len(a)-1] {
966-
r := i + d
967-
nxtR = max(nxtR, r)
968-
if i == curR { // 到达已建造的桥的右端点
969-
if i == nxtR { // 无论怎么造桥,都无法从 i 到 i+1
970-
return -1
971-
}
972-
curR = nxtR // 建造下一座桥
973-
ans++
974-
}
975-
}
976-
return
977-
}
978-
979905
// 摩尔投票法求绝对众数(absolute mode, majority)
980906
// Boyer–Moore majority vote algorithm
981907
// https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
@@ -1223,3 +1149,88 @@ func makeLexicographicallySmallestStringBySwappingAdjacentElements2(a []int) []i
12231149
}
12241150
return ans
12251151
}
1152+
1153+
// 解析时分
1154+
// - [1736. 替换隐藏数字得到的最晚时间](https://leetcode.cn/problems/latest-time-by-replacing-hidden-digits/) 1264
1155+
// - [3114. 替换字符可以得到的最晚时间](https://leetcode.cn/problems/latest-time-you-can-obtain-after-replacing-characters/) 1291
1156+
// - [2224. 转化时间需要的最少操作数](https://leetcode.cn/problems/minimum-number-of-operations-to-convert-time/) 1296
1157+
// - [2933. 高访问员工](https://leetcode.cn/problems/high-access-employees/) 1537
1158+
// 解析月日:LC2409 https://leetcode.cn/problems/count-days-spent-together/
1159+
func parseTime(s string) (hour, minute, total int) {
1160+
hour = int(s[0]&15)*10 + int(s[1]&15)
1161+
minute = int(s[3]&15)*10 + int(s[4]&15)
1162+
total = hour*60 + minute
1163+
return
1164+
}
1165+
1166+
// 从 i 可以跳到 [i,i+a[i]] 中的任意整点
1167+
// 返回从 0 跳到 n-1 的最小跳跃次数
1168+
// 如果无法到达 n-1,返回 -1
1169+
// 注:对于复杂变形题,采用分组循环不易写错
1170+
// - [45. 跳跃游戏 II](https://leetcode.cn/problems/jump-game-ii/)
1171+
// - [1024. 视频拼接](https://leetcode.cn/problems/video-stitching/) 1746
1172+
// - [1326. 灌溉花园的最少水龙头数目](https://leetcode.cn/problems/minimum-number-of-taps-to-open-to-water-a-garden/) 1885
1173+
// 【图解】https://leetcode.cn/problems/minimum-number-of-taps-to-open-to-water-a-garden/solution/yi-zhang-tu-miao-dong-pythonjavacgo-by-e-wqry/
1174+
// https://codeforces.com/problemset/problem/1630/C 2200 变形
1175+
// https://codeforces.com/problemset/problem/1066/B 1500 这题其实不算,但如果每个加热器的 r 不同,就是跳跃游戏 II 了
1176+
func minJumpNumbers(a []int) (ans int) {
1177+
curR := 0 // 已建造的桥的右端点
1178+
nxtR := 0 // 下一座桥的右端点的最大值
1179+
// 这里没有遍历到 n-1,因为它已经是终点了
1180+
for i, d := range a[:len(a)-1] {
1181+
r := i + d
1182+
nxtR = max(nxtR, r)
1183+
if i == curR { // 到达已建造的桥的右端点
1184+
if i == nxtR { // 无论怎么造桥,都无法从 i 到 i+1
1185+
return -1
1186+
}
1187+
curR = nxtR // 建造下一座桥
1188+
ans++
1189+
}
1190+
}
1191+
return
1192+
}
1193+
1194+
// 合并 a 中所有重叠的闭区间(哪怕只有一个端点重叠,也算重叠)
1195+
// 注意 [1,1] 和 [2,2] 不能合并成 [1,2]
1196+
// 注:这种做法在变形题中容易写错,更加稳定的做法是差分数组
1197+
// - [56. 合并区间](https://leetcode.cn/problems/merge-intervals/)
1198+
// - [55. 跳跃游戏](https://leetcode.cn/problems/jump-game/)
1199+
// - [763. 划分字母区间](https://leetcode.cn/problems/partition-labels/) 1443
1200+
// - [3169. 无需开会的工作日](https://leetcode.cn/problems/count-days-without-meetings/) ~1500
1201+
// - [2580. 统计将重叠区间合并成组的方案数](https://leetcode.cn/problems/count-ways-to-group-overlapping-ranges/) 1632
1202+
// - [2963. 统计好分割方案的数目](https://leetcode.cn/problems/count-the-number-of-good-partitions/) 1985
1203+
// - [2584. 分割数组使乘积互质](https://leetcode.cn/problems/split-the-array-to-make-coprime-products/) 2159
1204+
// - [2655. 寻找最大长度的未覆盖区间](https://leetcode.cn/problems/find-maximal-uncovered-ranges/)(会员题)
1205+
// 另见 common.go 中的「区间贪心」
1206+
// https://codeforces.com/problemset/problem/1626/C 1700
1207+
// - 倒序合并代码 https://codeforces.com/contest/1626/submission/211306494
1208+
// https://codeforces.com/problemset/problem/1859/D 1800
1209+
// https://codeforces.com/problemset/problem/1260/D 1900
1210+
func mergeIntervals(a [][]int) [][]int {
1211+
slices.SortFunc(a, func(a, b []int) int { return a[0] - b[0] }) // 按区间左端点排序
1212+
merged := [][]int{}
1213+
l0 := a[0][0]
1214+
maxR := a[0][1]
1215+
for _, p := range a[1:] { // 从第二个区间开始
1216+
l, r := p[0], p[1]
1217+
// 如果要合并 [1,1] 和 [2,2],下面改成 if l-1 > maxR
1218+
if l > maxR { // 发现一个新区间
1219+
merged = append(merged, []int{l0, maxR}) // 先把旧的加入答案
1220+
l0 = l // 记录新区间左端点
1221+
}
1222+
maxR = max(maxR, r)
1223+
}
1224+
merged = append(merged, []int{l0, maxR}) // 最后发现的新区间加入答案
1225+
1226+
{
1227+
// 包含 x 的闭区间
1228+
var x int
1229+
i := sort.Search(len(merged), func(i int) bool { return merged[i][1] >= x })
1230+
if i < len(merged) && merged[i][0] <= x {
1231+
// ans[i]...
1232+
}
1233+
}
1234+
1235+
return merged
1236+
}

copypasta/segment_tree01.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "math/bits"
1010
// https://www.luogu.com.cn/problem/P2572
1111
// https://codeforces.com/contest/1705/problem/E
1212
// https://codeforces.com/problemset/problem/877/E
13-
// http://codeforces.com/problemset/problem/145/E 2400
13+
// https://codeforces.com/problemset/problem/145/E 2400
1414
type seg01 []struct {
1515
l, r int
1616
ones int // EXTRA: 1 的个数

copypasta/stack.go

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

33
/*
4-
入门
4+
栈消除
55
LC735 https://leetcode.cn/problems/asteroid-collision/
66
- 变形:碰撞后,大行星的质量会减去的行星的质量
77
- 变形 2:你可以决定每颗行星的方向,问最后的行星质量之和最小是多少
88
-- f[i][j] 表示前 i 颗行星,向右的质量之和为 j 时,向左的质量之和的最小值
99
LC2751 https://leetcode.cn/problems/robot-collisions/
10+
https://atcoder.jp/contests/abc328/tasks/abc328_d
1011
1112
栈的应用
1213
栈+懒删除 https://codeforces.com/problemset/problem/1000/F

copypasta/treap.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ todo Merging treaps https://codeforces.com/blog/entry/108601
1818
1919
模板题 https://www.luogu.com.cn/problem/P3369 https://www.luogu.com.cn/problem/P6136
2020
题目推荐 https://cp-algorithms.com/data_structures/treap.html#toc-tgt-8
21-
较为复杂的维护 https://codeforces.com/problemset/problem/85/D
22-
离线+lowerbound+delete https://atcoder.jp/contests/abc245/tasks/abc245_e
21+
https://codeforces.com/problemset/problem/85/D 较为复杂的维护
22+
https://atcoder.jp/contests/abc245/tasks/abc245_e 离线+lowerbound+delete
23+
https://atcoder.jp/contests/abc356/tasks/abc356_f 维护关键位置
2324
*/
2425

2526
// 用 GoLand 的话强烈建议加入到 Live Templates 中,比赛时直接敲快捷键

copypasta/union_find.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
只有启发式合并(按深度合并)的并查集的复杂度也是 O(nlogn) 的,适用于可持久化的场景
1212
1313
只有路径压缩的并查集,可以构造一棵二项树(binomial tree)
14-
结合图片讲解 https://en.wikipedia.org/wiki/Binomial_heap
14+
结合图片讲解 https://upload.wikimedia.org/wikipedia/commons/c/cf/Binomial_Trees.svg (https://en.wikipedia.org/wiki/Binomial_heap)
1515
每次把二项树的根节点连到一个新的孤立点上,然后对最深的点调用 find
1616
这样可以得到一棵几乎一样的树(区别仅仅是根节点多了一个儿子)
1717
所以,只要重复上述过程,就可以让每次 find 都是 O(logn) 级别的了
@@ -43,9 +43,16 @@ https://zhuanlan.zhihu.com/p/553192435
4343
// 转换 https://atcoder.jp/contests/abc304/tasks/abc304_e
4444
// 转换 https://atcoder.jp/contests/abc238/tasks/abc238_e
4545
// merge 后 from 还有用 https://atcoder.jp/contests/abc279/tasks/abc279_f
46+
// 处理图上的环 https://codeforces.com/contest/1726/problem/D
4647
//
47-
// 处理图上的环
48-
// - https://codeforces.com/contest/1726/problem/D
48+
// 质因子并查集 GCD>1 并查集
49+
// 预处理质因子(见 math.go 中的 primeDivisorsAll)
50+
// 枚举 a[i] 的质因子 p,用 pre[p] 记录质因子上一次出现的下标(初始化成 -1),然后 merge(i, pre[p]) if pre[p] > 0
51+
// - [2709. 最大公约数遍历](https://leetcode.cn/problems/greatest-common-divisor-traversal/) 2172
52+
// - [1627. 带阈值的图连通性](https://leetcode.cn/problems/graph-connectivity-with-threshold/) 2221
53+
// - [952. 按公因数计算最大组件大小](https://leetcode.cn/problems/largest-component-size-by-common-factor/) 2272
54+
// 下标距离有上界 https://codeforces.com/contest/1978/problem/F
55+
// - [1998. 数组的最大公因数排序](https://leetcode.cn/problems/gcd-sort-of-an-array/) 2429
4956
//
5057
// 数组标记/区间合并相关
5158
// - 经典模型是一维区间覆盖染色,通过倒序+并查集解决
@@ -298,6 +305,7 @@ func _(n int) {
298305
}
299306

300307
// 用并查集实现有序集合的删除、查找前驱和查找后继
308+
// 无法构造一棵二项树,单次操作均摊复杂度是 O(1) 的
301309
// LC https://leetcode.cn/problems/block-placement-queries/
302310
type delUf struct {
303311
left []int
@@ -441,23 +449,24 @@ func _(n int) {
441449
// https://cp-algorithms.com/data_structures/disjoint_set_union.html#toc-tgt-11
442450
// https://cp-algorithms.com/data_structures/disjoint_set_union.html#toc-tgt-12
443451
// https://oi-wiki.org/ds/dsu/#_9
444-
// 模板题 https://codeforces.com/contest/1850/problem/H
445-
// https://codeforces.com/problemset/problem/1074/D
452+
//
453+
// 模板题 https://codeforces.com/problemset/problem/1850/H 1700
454+
// https://codeforces.com/problemset/problem/1074/D 2400? 1700!
446455
// https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/D
447-
// 种类并查集:同义词反义词 https://codeforces.com/problemset/problem/766/D
448-
// 种类并查集:狼人和平民 https://codeforces.com/problemset/problem/1594/D
456+
// 种类并查集:狼人和平民 https://codeforces.com/problemset/problem/1594/D 1700
457+
// 种类并查集:同义词反义词 https://codeforces.com/problemset/problem/766/D 2000
449458
// 种类并查集:食物链 https://www.luogu.com.cn/problem/P2024
450459
// 种类并查集:不能构成二分图的第一条边 https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/J
451-
// 种类并查集 + 维护集合大小 https://codeforces.com/problemset/problem/1290/C
460+
// 种类并查集 + 维护集合大小 https://codeforces.com/problemset/problem/1290/C 2400
452461
// todo https://codeforces.com/contest/1615/problem/D
453462
// https://codeforces.com/contest/1713/problem/E
454463
// 边权:https://codeforces.com/edu/course/2/lesson/7/1/practice/contest/289390/problem/C
455464
// 边权:LC399 除法求值 https://leetcode.cn/problems/evaluate-division/
456465
// LC2307 https://leetcode.cn/problems/check-for-contradictions-in-equations/ 也可以 DFS
457-
// https://codeforces.com/problemset/problem/1788/F
466+
// https://codeforces.com/problemset/problem/1788/F 2500
458467
func _(n int) {
459468
// 注:kinds 为 2 时可以用异或来代替加减法
460-
const kinds = 2
469+
const kinds = 3
461470
fa := make([]int, n) // n+1
462471
for i := range fa {
463472
fa[i] = i
@@ -472,8 +481,11 @@ func _(n int) {
472481
}
473482
return fa[x]
474483
}
475-
// 调用前需要保证 same(x, y) 为 true
484+
same := func(x, y int) bool { return find(x) == find(y) }
476485
delta := func(x, y int) int {
486+
if !same(x, y) { // 如果题目保证 same,则可以去掉
487+
return -1
488+
}
477489
find(x)
478490
find(y)
479491
return ((dis[x]-dis[y])%kinds + kinds) % kinds
@@ -486,7 +498,6 @@ func _(n int) {
486498
}
487499
return delta(from, to) == d
488500
}
489-
same := func(x, y int) bool { return find(x) == find(y) }
490501

491502
// 统计每个集合中各个类型的个数
492503
cnt := make([][kinds]int, len(fa))
@@ -600,6 +611,7 @@ func (o *pufNode) merge(x, y int) *pufNode {
600611
// https://loj.ac/p/121
601612
// https://atcoder.jp/contests/abc302/tasks/abc302_h (基于 https://atcoder.jp/contests/arc111/tasks/arc111_b)
602613
// todo https://codeforces.com/contest/891/problem/C
614+
// https://codeforces.com/problemset/problem/1217/F
603615
// https://codeforces.com/contest/1681/problem/F
604616
// todo Dynamic connectivity contest https://codeforces.com/gym/100551
605617
func dynamicConnectivity(in io.Reader, n, q int) (ans []int) {

0 commit comments

Comments
 (0)