ac-library-rb 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/lock_lib.rb +5 -1
- data/document_ja/lazy_segtree.md +9 -7
- data/document_ja/segtree.md +6 -2
- data/lib/ac-library-rb/version.rb +1 -1
- data/lib/floor_sum.rb +4 -6
- data/lib/min_cost_flow.rb +3 -3
- data/lib_lock/ac-library-rb/core_ext/modint.rb +3 -3
- data/lib_lock/ac-library-rb/floor_sum.rb +4 -6
- data/lib_lock/ac-library-rb/min_cost_flow.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb356bb0c8bcb397f6422ce68964cfc7cdb3bda6915b91e1c57a20045e789407
|
4
|
+
data.tar.gz: de638d458475278d7c34fe2a79633592e7c17325c27e6725b4a8a59f8049e7e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2802262ebc08af6b69cd20c7f756aea82c17b3e5ed242e94d1b2f7934ee36a519375ef0f4a1eb2e2188b740ee7669e63755996c74984a69e9bd0417de3141f7
|
7
|
+
data.tar.gz: 44dc88cad01600c5696b97230e332cf646a5d5c4e5cb2d73937eaae2d66008c43656284e702a523d152039ec7c53daf71ede355763bb9416339313cb356456ca
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ This is not limited to ac-library-rb, but I will show you how to install the two
|
|
37
37
|
- By `gem` command, `gem install ac-library-rb`.
|
38
38
|
- By using the gem bundler's commands.
|
39
39
|
|
40
|
-
By
|
40
|
+
#### By gem command, `gem install ac-library-rb`
|
41
41
|
|
42
42
|
Execute `gem install ac-library-rb` by using the gem command included in Ruby itself.
|
43
43
|
|
data/bin/lock_lib.rb
CHANGED
@@ -17,6 +17,10 @@ Dir.glob(lib_path) do |file|
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# copy library from `lib/core_ext` to `lib_lock/ac-library-rb/core_ext`
|
20
|
+
ac_library_rb_classes = %w[ModInt]
|
21
|
+
replaces = ac_library_rb_classes.to_h{ |cls| ["#{cls}.new", "AcLibraryRb::#{cls}.new"] }
|
22
|
+
pattern = Regexp.new(replaces.keys.join('|'))
|
23
|
+
|
20
24
|
lib_path = File.expand_path('../lib/core_ext/**', __dir__)
|
21
25
|
lock_dir = File.expand_path('../lib_lock/ac-library-rb/core_ext', __dir__)
|
22
26
|
Dir.glob(lib_path) do |file|
|
@@ -24,6 +28,6 @@ Dir.glob(lib_path) do |file|
|
|
24
28
|
|
25
29
|
path = Pathname.new(lock_dir) + Pathname.new(file).basename
|
26
30
|
File.open(path, "w") do |f|
|
27
|
-
f.puts File.readlines(file)
|
31
|
+
f.puts File.readlines(file).map{ |text| text.gsub(pattern, replaces) }
|
28
32
|
end
|
29
33
|
end
|
data/document_ja/lazy_segtree.md
CHANGED
@@ -132,7 +132,7 @@ LazySegtree上で、二分探索をします。
|
|
132
132
|
## Verified
|
133
133
|
|
134
134
|
問題のリンクです。Verified済みです。解答はテストコードをご参考ください。
|
135
|
-
- [AIZU ONLINE JUDGE DSL\_2\_F RMQ and RUQ](
|
135
|
+
- [AIZU ONLINE JUDGE DSL\_2\_F RMQ and RUQ](https://onlinejudge.u-aizu.ac.jp/problems/DSL_2_F) ([旧DSL_2_F](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F))
|
136
136
|
- [AIZU ONLINE JUDGE DSL\_2\_G RSQ and RAQ](https://onlinejudge.u-aizu.ac.jp/problems/DSL_2_G) ([旧DSL_2_G](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G))
|
137
137
|
- [AIZU ONLINE JUDGE DSL\_2\_H RMQ and RAQ](https://onlinejudge.u-aizu.ac.jp/problems/DSL_2_H) ([旧DSL_2_H](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_H))
|
138
138
|
- [AIZU ONLINE JUDGE DSL\_2\_I RSQ and RUQ](https://onlinejudge.u-aizu.ac.jp/problems/DSL_2_I) ([旧DSL_2_I](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_I))
|
@@ -155,13 +155,15 @@ LazySegtree上で、二分探索をします。
|
|
155
155
|
- [本家ライブラリの実装コード lazysegtree.hpp(GitHub)](https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp)
|
156
156
|
- [本家ライブラリのテストコード lazysegtree_test.cpp(GitHub)](https://github.com/atcoder/ac-library/blob/master/test/unittest/lazysegtree_test.cpp)
|
157
157
|
- セグメントツリーについて
|
158
|
-
- [
|
159
|
-
- [
|
158
|
+
- [2017/3 hogecoder: セグメント木をソラで書きたいあなたに](https://tsutaj.hatenablog.com/entry/2017/03/29/204841)
|
159
|
+
- [2017/3 hogecoder: 遅延評価セグメント木をソラで書きたいあなたに](https://tsutaj.hatenablog.com/entry/2017/03/30/224339)
|
160
|
+
- [2017/7 はまやんはまやんはまやん: 競技プログラミングにおけるセグメントツリー問題まとめ](https://blog.hamayanhamayan.com/entry/2017/07/08/173120)
|
161
|
+
- [2020/2 ageprocpp Qiita: Segment Treeことはじめ【後編】](https://qiita.com/ageprocpp/items/9ea58ac181d31cfdfe02)
|
160
162
|
- AtCooderLibrary(ACL)のLazySegtreeについて
|
161
|
-
- [
|
162
|
-
- [
|
163
|
-
- [ACLPC: K–Range Affine Range Sumの解説
|
164
|
-
- [
|
163
|
+
- [2020/9/22 ARMERIA: 使い方](https://betrue12.hateblo.jp/entry/2020/09/22/194541)
|
164
|
+
- [2020/9/23 ARMERIA: チートシート](https://betrue12.hateblo.jp/entry/2020/09/23/005940)
|
165
|
+
- [2020/9/27 optのブログ: ACLPC: K–Range Affine Range Sumの解説](https://opt-cp.com/cp/lazysegtree-aclpc-k/)
|
166
|
+
- [2020/9/27 buyoh.hateblo.jp: ACL 基礎実装例集](https://buyoh.hateblo.jp/entry/2020/09/27/190144)
|
165
167
|
|
166
168
|
## 本家ライブラリとの違い
|
167
169
|
|
data/document_ja/segtree.md
CHANGED
@@ -127,14 +127,18 @@ Segtree上で二分探索をします。
|
|
127
127
|
- [当ライブラリの実装コード segtree.rb](https://github.com/universato/ac-library-rb/blob/master/lib/segtree.rb)
|
128
128
|
- [当ライブラリのテストコード segtree.rb](https://github.com/universato/ac-library-rb/blob/master/test/segtree_test.rb)
|
129
129
|
- テストコードも具体的な使い方として役に立つかもしれまん。
|
130
|
-
-
|
130
|
+
- 本家ライブラリ
|
131
131
|
- [本家ライブラリのドキュメント segtree.md(GitHub)](https://github.com/atcoder/ac-library/blob/master/document_ja/segtree.md)
|
132
132
|
- [本家のドキュメント appendix.md(GitHub)](https://github.com/atcoder/ac-library/blob/master/document_ja/appendix.md)
|
133
133
|
- [本家ライブラリの実装コード segtree.hpp(GitHub)](https://github.com/atcoder/ac-library/blob/master/atcoder/segtree.hpp)
|
134
134
|
- [本家ライブラリのテストコード segtree_test.cpp(GitHub)](https://github.com/atcoder/ac-library/blob/master/test/unittest/segtree_test.cpp)
|
135
135
|
- [本家ライブラリのサンプルコード segtree_practice.cpp(GitHub)](https://github.com/atcoder/ac-library/blob/master/test/example/segtree_practice.cpp)
|
136
136
|
- セグメントツリーについて
|
137
|
-
- [
|
137
|
+
- [2017/3 hogecoder: セグメント木をソラで書きたいあなたに](https://tsutaj.hatenablog.com/entry/2017/03/29/204841)
|
138
|
+
- [2017/7 はまやんはまやんはまやん: 競技プログラミングにおけるセグメントツリー問題まとめ](https://blog.hamayanhamayan.com/entry/2017/07/08/173120)
|
139
|
+
- [2017/12 ei1333の日記: ちょっと変わったセグメント木の使い方](https://ei1333.hateblo.jp/entry/2017/12/14/000000)
|
140
|
+
スライドが二分探索について詳しい
|
141
|
+
- [2020/2 ageprocpp@Qiita: Segment Treeことはじめ【前編](https://qiita.com/ageprocpp/items/f22040a57ad25d04d199)
|
138
142
|
|
139
143
|
## 本家ライブラリとの違い等
|
140
144
|
|
data/lib/floor_sum.rb
CHANGED
@@ -2,7 +2,7 @@ def floor_sum(n, m, a, b)
|
|
2
2
|
res = 0
|
3
3
|
|
4
4
|
if a >= m
|
5
|
-
res += (n - 1) * n * (a / m)
|
5
|
+
res += (n - 1) * n / 2 * (a / m)
|
6
6
|
a %= m
|
7
7
|
end
|
8
8
|
|
@@ -11,11 +11,9 @@ def floor_sum(n, m, a, b)
|
|
11
11
|
b %= m
|
12
12
|
end
|
13
13
|
|
14
|
-
y_max =
|
14
|
+
y_max = a * n + b
|
15
|
+
return res if y_max < m
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
x_max = (m * y_max - b + a - 1) / a
|
19
|
-
res += (n - x_max) * y_max + floor_sum(y_max, a, m, a * x_max - m * y_max + b)
|
17
|
+
res += floor_sum(y_max / m, a, m, y_max % m)
|
20
18
|
res
|
21
19
|
end
|
data/lib/min_cost_flow.rb
CHANGED
@@ -104,7 +104,7 @@ class MinCostFlow
|
|
104
104
|
def slope(s, t, flow_limit = Float::MAX)
|
105
105
|
flow = 0
|
106
106
|
cost = 0
|
107
|
-
|
107
|
+
prev_cost_per_flow = -1
|
108
108
|
result = [[flow, cost]]
|
109
109
|
|
110
110
|
while flow < flow_limit
|
@@ -129,9 +129,9 @@ class MinCostFlow
|
|
129
129
|
d = -@dual[s]
|
130
130
|
flow += c
|
131
131
|
cost += c * d
|
132
|
-
result.pop if
|
132
|
+
result.pop if prev_cost_per_flow == d
|
133
133
|
result << [flow, cost]
|
134
|
-
|
134
|
+
prev_cost_per_flow = d
|
135
135
|
end
|
136
136
|
|
137
137
|
result
|
@@ -1,11 +1,11 @@
|
|
1
1
|
def ModInt(val)
|
2
|
-
ModInt.new(val)
|
2
|
+
AcLibraryRb::ModInt.new(val)
|
3
3
|
end
|
4
4
|
|
5
5
|
# Integer
|
6
6
|
class Integer
|
7
7
|
def to_modint
|
8
|
-
ModInt.new(self)
|
8
|
+
AcLibraryRb::ModInt.new(self)
|
9
9
|
end
|
10
10
|
alias to_m to_modint
|
11
11
|
end
|
@@ -13,7 +13,7 @@ end
|
|
13
13
|
# String
|
14
14
|
class String
|
15
15
|
def to_modint
|
16
|
-
ModInt.new(to_i)
|
16
|
+
AcLibraryRb::ModInt.new(to_i)
|
17
17
|
end
|
18
18
|
alias to_m to_modint
|
19
19
|
end
|
@@ -3,7 +3,7 @@ module AcLibraryRb
|
|
3
3
|
res = 0
|
4
4
|
|
5
5
|
if a >= m
|
6
|
-
res += (n - 1) * n * (a / m)
|
6
|
+
res += (n - 1) * n / 2 * (a / m)
|
7
7
|
a %= m
|
8
8
|
end
|
9
9
|
|
@@ -12,12 +12,10 @@ module AcLibraryRb
|
|
12
12
|
b %= m
|
13
13
|
end
|
14
14
|
|
15
|
-
y_max =
|
15
|
+
y_max = a * n + b
|
16
|
+
return res if y_max < m
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
x_max = (m * y_max - b + a - 1) / a
|
20
|
-
res += (n - x_max) * y_max + floor_sum(y_max, a, m, a * x_max - m * y_max + b)
|
18
|
+
res += floor_sum(y_max / m, a, m, y_max % m)
|
21
19
|
res
|
22
20
|
end
|
23
21
|
end
|
@@ -105,7 +105,7 @@ module AcLibraryRb
|
|
105
105
|
def slope(s, t, flow_limit = Float::MAX)
|
106
106
|
flow = 0
|
107
107
|
cost = 0
|
108
|
-
|
108
|
+
prev_cost_per_flow = -1
|
109
109
|
result = [[flow, cost]]
|
110
110
|
|
111
111
|
while flow < flow_limit
|
@@ -130,9 +130,9 @@ module AcLibraryRb
|
|
130
130
|
d = -@dual[s]
|
131
131
|
flow += c
|
132
132
|
cost += c * d
|
133
|
-
result.pop if
|
133
|
+
result.pop if prev_cost_per_flow == d
|
134
134
|
result << [flow, cost]
|
135
|
-
|
135
|
+
prev_cost_per_flow = d
|
136
136
|
end
|
137
137
|
|
138
138
|
result
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ac-library-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- universato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|