Skip to content

Commit 68a7b46

Browse files
committed
upd
1 parent b83825e commit 68a7b46

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

copypasta/mo.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
. "fmt"
55
"io"
66
"math"
7+
"slices"
78
"sort"
89
)
910

@@ -33,44 +34,43 @@ import (
3334
//
3435
// https://oi-wiki.org/misc/mo-algo/
3536
// 模板题 https://www.luogu.com.cn/problem/P1494
36-
// todo https://www.luogu.com.cn/problem/P2709
37-
// todo https://www.luogu.com.cn/problem/P4462
38-
// 恰好出现两次 https://www.luogu.com.cn/problem/P7764
39-
// https://www.luogu.com.cn/problem/P5673
40-
// https://ac.nowcoder.com/acm/problem/25458
41-
// 至少出现两次 https://ac.nowcoder.com/acm/problem/20545
42-
// 至少出现 k 次 https://codeforces.com/problemset/problem/375/D
43-
// 至少出现 k 次 https://www.codechef.com/problems/KCHIPS
37+
// https://www.luogu.com.cn/problem/P2709
38+
// https://www.luogu.com.cn/problem/P4462
39+
// 恰好出现两次 https://www.luogu.com.cn/problem/P7764
40+
// https://www.luogu.com.cn/problem/P5673
41+
// https://ac.nowcoder.com/acm/problem/25458
42+
// 至少出现两次 https://ac.nowcoder.com/acm/problem/20545
43+
// 至少出现 k 次 https://codeforces.com/problemset/problem/375/D
44+
// 至少出现 k 次 https://www.codechef.com/problems/KCHIPS
4445
// https://codeforces.com/contest/220/problem/B
4546
// https://atcoder.jp/contests/abc242/tasks/abc242_g
4647
// https://atcoder.jp/contests/abc293/tasks/abc293_g
4748
// 区间 mex https://blog.csdn.net/includelhc/article/details/79593496
4849
// 反向构造题 https://www.luogu.com.cn/problem/P6852
49-
// todo https://codeforces.com/contest/86/problem/D
50-
// https://codeforces.com/contest/617/problem/E
51-
// https://codeforces.com/contest/877/problem/F
52-
// https://www.codechef.com/problems/QCHEF
50+
// https://codeforces.com/contest/86/problem/D
51+
// https://codeforces.com/problemset/problem/617/E 2200
52+
// https://codeforces.com/contest/877/problem/F
53+
// https://www.codechef.com/problems/QCHEF
5354
func normalMo(a []int, queries [][]int) []int {
5455
n := len(a)
5556
m := len(queries)
5657
blockSize := int(math.Ceil(float64(n) / math.Sqrt(float64(m))))
57-
type moQuery struct{ lb, l, r, qid int } // [l,r)
58+
type moQuery struct{ bid, l, r, qid int } // [l,r)
5859
qs := make([]moQuery, m)
5960
for i, q := range queries {
6061
// 输入是从 1 开始的
6162
l, r := q[0], q[1] // read...
6263
qs[i] = moQuery{l / blockSize, l, r + 1, i}
6364
}
64-
sort.Slice(qs, func(i, j int) bool {
65-
a, b := qs[i], qs[j]
66-
if a.lb != b.lb {
67-
return a.lb < b.lb
65+
slices.SortFunc(qs, func(a, b moQuery) int {
66+
if a.bid != b.bid {
67+
return a.bid - b.bid
6868
}
6969
// 奇偶化排序
70-
if a.lb&1 == 0 {
71-
return a.r < b.r
70+
if a.bid&1 == 0 {
71+
return a.r - b.r
7272
}
73-
return a.r > b.r
73+
return b.r - a.r
7474
})
7575

7676
cnt := 0

0 commit comments

Comments
 (0)