ac-library-rb 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/unittest.yml +16 -3
- data/.rubocop.yml +61 -45
- data/README.ja.md +36 -8
- data/README.md +7 -4
- data/Rakefile +7 -3
- data/ac-library-rb.gemspec +11 -4
- data/ac-library-rb_header.jpg +0 -0
- data/bin/console +1 -1
- data/document_en/dsu.md +1 -1
- data/document_en/fenwick_tree.md +2 -2
- data/document_en/lazy_segtree.md +4 -4
- data/document_en/math.md +3 -3
- data/document_en/max_flow.md +3 -3
- data/document_en/min_cost_flow.md +4 -4
- data/document_en/modint.md +4 -4
- data/document_en/scc.md +67 -0
- data/document_en/segtree.md +2 -2
- data/document_ja/dsu.md +1 -1
- data/document_ja/fenwick_tree.md +2 -2
- data/document_ja/lazy_segtree.md +2 -2
- data/document_ja/math.md +3 -3
- data/document_ja/max_flow.md +4 -7
- data/document_ja/min_cost_flow.md +5 -4
- data/document_ja/modint.md +4 -4
- data/document_ja/scc.md +9 -8
- data/document_ja/segtree.md +2 -2
- data/lib/ac-library-rb/version.rb +1 -1
- data/lib/convolution.rb +1 -1
- data/lib/dsu.rb +14 -1
- data/lib/fenwick_tree.rb +4 -0
- data/lib/lazy_segtree.rb +2 -6
- data/lib/max_flow.rb +27 -26
- data/lib/modint.rb +4 -4
- data/lib/priority_queue.rb +14 -0
- data/lib/scc.rb +1 -1
- data/lib/two_sat.rb +1 -1
- data/lib_lock/ac-library-rb/convolution.rb +1 -1
- data/lib_lock/ac-library-rb/dsu.rb +14 -1
- data/lib_lock/ac-library-rb/fenwick_tree.rb +4 -0
- data/lib_lock/ac-library-rb/lazy_segtree.rb +2 -6
- data/lib_lock/ac-library-rb/max_flow.rb +27 -26
- data/lib_lock/ac-library-rb/modint.rb +4 -4
- data/lib_lock/ac-library-rb/priority_queue.rb +14 -0
- data/lib_lock/ac-library-rb/scc.rb +1 -1
- data/lib_lock/ac-library-rb/two_sat.rb +1 -1
- metadata +39 -7
@@ -5,7 +5,7 @@ module AcLibraryRb
|
|
5
5
|
class ModInt < Numeric
|
6
6
|
class << self
|
7
7
|
def set_mod(mod)
|
8
|
-
raise ArgumentError unless mod.is_a?
|
8
|
+
raise ArgumentError unless mod.is_a?(Integer) && (1 <= mod)
|
9
9
|
|
10
10
|
$_mod = mod
|
11
11
|
$_mod_is_prime = ModInt.prime?(mod)
|
@@ -27,7 +27,7 @@ module AcLibraryRb
|
|
27
27
|
|
28
28
|
def prime?(n)
|
29
29
|
return false if n <= 1
|
30
|
-
return true if n == 2
|
30
|
+
return true if (n == 2) || (n == 7) || (n == 61)
|
31
31
|
return false if (n & 1) == 0
|
32
32
|
|
33
33
|
d = n - 1
|
@@ -35,11 +35,11 @@ module AcLibraryRb
|
|
35
35
|
[2, 7, 61].each do |a|
|
36
36
|
t = d
|
37
37
|
y = a.pow(t, n)
|
38
|
-
while t != n - 1
|
38
|
+
while (t != n - 1) && (y != 1) && (y != n - 1)
|
39
39
|
y = y * y % n
|
40
40
|
t <<= 1
|
41
41
|
end
|
42
|
-
return false if y != n - 1
|
42
|
+
return false if (y != n - 1) && ((t & 1) == 0)
|
43
43
|
end
|
44
44
|
true
|
45
45
|
end
|
@@ -14,11 +14,17 @@ module AcLibraryRb
|
|
14
14
|
heapify
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.[](*array, &comp)
|
18
|
+
new(array, &comp)
|
19
|
+
end
|
20
|
+
|
17
21
|
attr_reader :heap
|
22
|
+
alias to_a heap
|
18
23
|
|
19
24
|
# Push new element to the heap.
|
20
25
|
def push(item)
|
21
26
|
shift_down(0, @heap.push(item).size - 1)
|
27
|
+
self
|
22
28
|
end
|
23
29
|
|
24
30
|
alias << push
|
@@ -47,6 +53,14 @@ module AcLibraryRb
|
|
47
53
|
@heap.empty?
|
48
54
|
end
|
49
55
|
|
56
|
+
def size
|
57
|
+
@heap.size
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s
|
61
|
+
"<#{self.class}: @heap:(#{heap.join(', ')}), @comp:<#{@comp.class} #{@comp.source_location.join(':')}>>"
|
62
|
+
end
|
63
|
+
|
50
64
|
private
|
51
65
|
|
52
66
|
def heapify
|
@@ -9,7 +9,7 @@ module AcLibraryRb
|
|
9
9
|
|
10
10
|
# add directed edge
|
11
11
|
def add_edge(from, to)
|
12
|
-
unless 0 <= from && from < @n
|
12
|
+
unless 0 <= from && from < @n && 0 <= to && to < @n
|
13
13
|
msg = "Wrong params: from=#{from} and to=#{to} must be in 0...#{@n}"
|
14
14
|
raise ArgumentError.new(msg)
|
15
15
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ac-library-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- universato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: prime
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,9 +66,24 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
|
-
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov-cobertura
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: |
|
56
84
|
ac-library-rb is a ruby port of AtCoder Library (ACL).
|
57
|
-
DSU(UnionFind), FenwickTree, PriorityQueue, Segtree, SCC, 2-SAT,
|
85
|
+
DSU(UnionFind), FenwickTree, PriorityQueue, Segtree, SCC, 2-SAT,
|
86
|
+
suffix_array, lcp_array, z_algorithm, crt, inv_mod, floor_sum, max_flow, min_cost_flow......
|
58
87
|
email:
|
59
88
|
- universato@gmail.com
|
60
89
|
executables: []
|
@@ -70,6 +99,7 @@ files:
|
|
70
99
|
- README.md
|
71
100
|
- Rakefile
|
72
101
|
- ac-library-rb.gemspec
|
102
|
+
- ac-library-rb_header.jpg
|
73
103
|
- bin/console
|
74
104
|
- bin/lock_lib.rb
|
75
105
|
- bin/setup
|
@@ -84,6 +114,7 @@ files:
|
|
84
114
|
- document_en/min_cost_flow.md
|
85
115
|
- document_en/modint.md
|
86
116
|
- document_en/priority_queue.md
|
117
|
+
- document_en/scc.md
|
87
118
|
- document_en/segtree.md
|
88
119
|
- document_en/string.md
|
89
120
|
- document_en/two_sat.md
|
@@ -151,23 +182,24 @@ licenses:
|
|
151
182
|
metadata:
|
152
183
|
homepage_uri: https://github.com/universato/ac-library-rb
|
153
184
|
source_code_uri: https://github.com/universato/ac-library-rb
|
185
|
+
rubygems_mfa_required: 'true'
|
154
186
|
post_install_message:
|
155
187
|
rdoc_options: []
|
156
188
|
require_paths:
|
157
189
|
- lib_lock
|
158
|
-
- lib_helpers
|
190
|
+
- lib_helpers"
|
159
191
|
required_ruby_version: !ruby/object:Gem::Requirement
|
160
192
|
requirements:
|
161
193
|
- - ">="
|
162
194
|
- !ruby/object:Gem::Version
|
163
|
-
version: 2.
|
195
|
+
version: 2.7.0
|
164
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
197
|
requirements:
|
166
198
|
- - ">="
|
167
199
|
- !ruby/object:Gem::Version
|
168
200
|
version: '0'
|
169
201
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
202
|
+
rubygems_version: 3.3.3
|
171
203
|
signing_key:
|
172
204
|
specification_version: 4
|
173
205
|
summary: ac-library-rb is a ruby port of AtCoder Library (ACL).
|