ac-library-rb 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -0
- data/README.ja.md +102 -4
- data/README.md +73 -1
- data/Rakefile +2 -1
- data/ac-library-rb.gemspec +3 -2
- data/bin/lock_lib.rb +13 -7
- data/document_en/dsu.md +2 -2
- data/document_en/lazy_segtree.md +20 -4
- data/document_en/max_flow.md +1 -1
- data/document_en/min_cost_flow.md +1 -1
- data/document_en/segtree.md +36 -3
- data/document_en/two_sat.md +1 -1
- data/document_ja/dsu.md +1 -3
- data/document_ja/lazy_segtree.md +63 -19
- data/document_ja/max_flow.md +1 -1
- data/document_ja/min_cost_flow.md +1 -1
- data/document_ja/scc.md +4 -3
- data/document_ja/segtree.md +49 -8
- data/document_ja/two_sat.md +1 -1
- data/lib/ac-library-rb/version.rb +1 -1
- data/lib/convolution.rb +21 -0
- data/lib/core_ext/all.rb +11 -0
- data/lib/dsu.rb +9 -6
- data/lib/fenwick_tree.rb +22 -8
- data/lib/floor_sum.rb +33 -10
- data/lib/lazy_segtree.rb +83 -10
- data/lib/max_flow.rb +10 -4
- data/lib/min_cost_flow.rb +13 -7
- data/lib/modint.rb +3 -1
- data/lib/scc.rb +21 -13
- data/lib/segtree.rb +38 -26
- data/lib/suffix_array.rb +8 -8
- data/lib/two_sat.rb +5 -3
- data/lib_lock/ac-library-rb.rb +2 -0
- data/lib_lock/ac-library-rb/convolution.rb +21 -0
- data/lib_lock/ac-library-rb/core_ext/all.rb +11 -0
- data/lib_lock/ac-library-rb/core_ext/modint.rb +3 -3
- data/lib_lock/ac-library-rb/dsu.rb +9 -6
- data/lib_lock/ac-library-rb/fenwick_tree.rb +22 -8
- data/lib_lock/ac-library-rb/floor_sum.rb +33 -10
- data/lib_lock/ac-library-rb/lazy_segtree.rb +83 -10
- data/lib_lock/ac-library-rb/max_flow.rb +10 -4
- data/lib_lock/ac-library-rb/min_cost_flow.rb +13 -7
- data/lib_lock/ac-library-rb/modint.rb +3 -1
- data/lib_lock/ac-library-rb/scc.rb +21 -13
- data/lib_lock/ac-library-rb/segtree.rb +38 -26
- data/lib_lock/ac-library-rb/suffix_array.rb +8 -8
- data/lib_lock/ac-library-rb/two_sat.rb +5 -3
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f191f90563fea038c7181e2bf9d13e1dc8caa0e816a364176e46b67c8d63f471
|
4
|
+
data.tar.gz: c89db082816046146cb60faa3747e046877394bfff776a3defe8063fb2d1c390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0114099d09f9566741d84ed2b5e43427b62592bb8b2a6b90d25b9f68288d2a387f34899351d18a7b3e0c93ec72af9cae4aac2f1d38f5fe517e30ec850e33429e'
|
7
|
+
data.tar.gz: cdb1eac1808855f86c00c991b4c66ae3489035420ef0fdb8c88915712ace8faa5db02da074a78734e0c4235058ac1e2a62a0fc9cc0523e6c85aff4617b47ae39
|
data/.rubocop.yml
CHANGED
@@ -91,6 +91,7 @@ Naming/FileName:
|
|
91
91
|
- 'lib_lock/ac-library-rb.rb'
|
92
92
|
Naming/AccessorMethodName:
|
93
93
|
Exclude:
|
94
|
+
- 'lib/lazy_segtree.rb'
|
94
95
|
- 'lib/modint.rb'
|
95
96
|
Naming/MethodName:
|
96
97
|
Exclude:
|
@@ -100,6 +101,9 @@ Naming/MethodName:
|
|
100
101
|
- 'test/convolution_test.rb'
|
101
102
|
Naming/MethodParameterName:
|
102
103
|
Enabled: false
|
104
|
+
Naming/VariableNumber:
|
105
|
+
Exclude:
|
106
|
+
- 'test/max_flow_test.rb'
|
103
107
|
Style/AndOr:
|
104
108
|
Enabled: false
|
105
109
|
Style/ArrayCoercion:
|
@@ -117,12 +121,19 @@ Style/BlockDelimiters:
|
|
117
121
|
- 'test/z_algorithm_test.rb'
|
118
122
|
Style/Documentation:
|
119
123
|
Enabled: false
|
124
|
+
tyle/EmptyElse:
|
125
|
+
Exclude:
|
126
|
+
- 'test/segtree_test.rb'
|
120
127
|
Style/GlobalVars:
|
121
128
|
AutoCorrect: false
|
122
129
|
Exclude:
|
123
130
|
- 'lib/modint.rb'
|
131
|
+
- 'test/lazy_segtree_test.rb'
|
124
132
|
Style/FrozenStringLiteralComment:
|
125
133
|
Enabled: false
|
134
|
+
Style/InfiniteLoop:
|
135
|
+
Exclude:
|
136
|
+
- 'lib/floor_sum.rb'
|
126
137
|
Style/InverseMethods:
|
127
138
|
AutoCorrect: false
|
128
139
|
Exclude:
|
@@ -176,6 +187,7 @@ Style/SelfAssignment:
|
|
176
187
|
Style/Semicolon:
|
177
188
|
Exclude:
|
178
189
|
- 'lib/lazy_segtree.rb'
|
190
|
+
- 'test/lazy_segtree_test.rb'
|
179
191
|
Style/SlicingWithRange:
|
180
192
|
Enabled: false
|
181
193
|
Style/SpecialGlobalVars:
|
data/README.ja.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# ac-library-rb
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/ac-library-rb)
|
4
|
+
|
3
5
|
ac-library-rbは、AtCoder Library (ACL)のRuby版です。
|
4
6
|
|
5
7
|
ACLの詳細は、以下をご覧ください.
|
@@ -15,13 +17,88 @@ ACLの詳細は、以下をご覧ください.
|
|
15
17
|
|
16
18
|
[ライブラリ目次: index.md](https://github.com/universato/ac-library-rb/blob/master/document_ja/index.md)
|
17
19
|
|
18
|
-
|
20
|
+
公式に、ac-library-rbの利用として、以下の方法を想定しています。
|
21
|
+
- 直接コピペして使う方法
|
22
|
+
- `lib`ディレクトリに、ac-library-rbのライブラリのコードがあります。
|
23
|
+
- `lib_lock`ディレクトリに、Gem用にモジュール化されたコードがあります。
|
24
|
+
(別途モジュール化するの、ちょっとトリッキーですが……)
|
25
|
+
- Gemとして使う方法(詳細は後述)
|
26
|
+
|
27
|
+
他に、有志作成のバンドルツール[expander-rb](https://github.com/surpace/expander-rb)(by surpaceさん)を利用する方法もあります。
|
28
|
+
|
29
|
+
目次は、[index.md](https://github.com/universato/ac-library-rb/blob/master/document_ja/index.md)をご覧ください。
|
30
|
+
|
31
|
+
## Gemとなったac-library-rbを使う方法
|
32
|
+
|
33
|
+
コピペ以外にGemとなったac-library-rbを使う方法を紹介します。
|
34
|
+
|
35
|
+
### gemのインストール方法
|
36
|
+
|
37
|
+
ac-library-rbに限った話ではないですが、一般的な2種類のgemのインストール方法を紹介します。
|
38
|
+
|
39
|
+
- Gemとして使う方法
|
40
|
+
- `gem`コマンドにより、`gem install ac-library-rb`
|
41
|
+
- gemのbundlerを用いる方法
|
42
|
+
|
43
|
+
#### gemコマンドによるインストール方法
|
44
|
+
|
45
|
+
Ruby本体に付属のgemコマンドを用い、そのまま`gem install ac-library-rb`を実行します。
|
46
|
+
|
47
|
+
#### gemのbundlerを用いたインストール方法
|
48
|
+
|
49
|
+
bundlerをインストールしてない場合は、`gem install bundler`というコマンドを打ちインストールします。
|
50
|
+
|
51
|
+
次に、ac-library-rbを使いたいディレクトリ配下にGemfileを置きます。Gemfileという名称のファイルです。
|
52
|
+
このGemfileの中で、次のように書きます。
|
53
|
+
```
|
54
|
+
gem "ac-library-rb"
|
55
|
+
```
|
56
|
+
そして、`budnle install`というコマンドにより、Gemfileに書かれたac-library-rbをインストールします。
|
57
|
+
|
58
|
+
このとき、bundlerを通してRubyファイルを実行する必要があるため、`bundle exec`コマンドを用います。
|
59
|
+
|
60
|
+
`$ bundle exec ruby sample.rb`
|
61
|
+
|
62
|
+
### (インストール後の)Rubyファイルでの書き方
|
63
|
+
|
64
|
+
#### 一括ロード
|
19
65
|
|
20
|
-
|
66
|
+
Rubyファイル上で一括でac-library-rbのライブラリを使えるようにするには、下記のように書きます。
|
21
67
|
|
22
|
-
|
68
|
+
```ruby
|
69
|
+
require "ac-library-rb/all"
|
23
70
|
|
24
|
-
|
71
|
+
dsu = AcLibraryRb::DSU.new
|
72
|
+
|
73
|
+
include AcLibraryRb
|
74
|
+
dsu = DSU.new
|
75
|
+
```
|
76
|
+
|
77
|
+
`include AcLibraryRb`とモジュールをインクルードすることで、
|
78
|
+
何度も`AcLibraryRb`といわゆる名前空間を書く必要がなくなります。
|
79
|
+
|
80
|
+
また、`/all`なしで`require "ac-library-rb"`とした場合は、`include AcLibraryRb`も同時に実行されます。
|
81
|
+
```ruby
|
82
|
+
require "ac-library-rb"
|
83
|
+
|
84
|
+
dsu = DSU.new
|
85
|
+
```
|
86
|
+
|
87
|
+
#### 個別ロード
|
88
|
+
|
89
|
+
特定のライブラリのみをインストールしたいときは下記のように`ac-library-rb/`のあとにライブラリ名を指定します。
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require "ac-library-rb/dsu"
|
93
|
+
dsu = AcLibraryRb::DSU.new
|
94
|
+
|
95
|
+
require "ac-library-rb/priority_queue"
|
96
|
+
pq = AcLibraryRb::PriorityQueue.new
|
97
|
+
```
|
98
|
+
|
99
|
+
本gem名はハイフン区切りですが、ac-library-rb内のライブラリ名はアンダースコア区切りであるため、注意して下さい。
|
100
|
+
一般的にRubyのライブラリ名はアンダースコアが推奨されていますが、
|
101
|
+
ACL本家のレポジトリ名がac-libraryとハイフン区切りで、それに合わせているため、レポジトリ名・gem名がハイフン区切りとなっています。
|
25
102
|
|
26
103
|
## Rubyバージョン
|
27
104
|
|
@@ -39,12 +116,33 @@ ACLの詳細は、以下をご覧ください.
|
|
39
116
|
|
40
117
|
宣伝・バグ報告などしてもらえると嬉しいです。
|
41
118
|
|
119
|
+
## ac-library-rbを開発したい方向けの情報
|
120
|
+
|
121
|
+
### コーディングスタイル
|
122
|
+
|
123
|
+
Rubocop(Rubyのlintツール)の設定ファイル`.rubocop.yml`は、参考に置いています。
|
124
|
+
Rubocopのルールを守ることが必ずしもよくなかったり、ルールを守ることが難しかったりもするので、Rubocopの適用は必須ではないです。
|
125
|
+
|
126
|
+
推奨スタイル
|
127
|
+
- インデントは、半角スペース2文字
|
128
|
+
- 行末の余計なスペースは削除
|
129
|
+
|
130
|
+
### ディレクトリの説明
|
131
|
+
|
132
|
+
`lib`ディレクトリ内に各種のデータ構造などのライブラリがあります。
|
133
|
+
`lib_lock`は、Gem用にモジュール化させるため`lib`の内容をコピーする形でモジュール化させています。
|
134
|
+
`bin/lock_lib.rb`を実行することで、`lib`から`lib_lock`にモジュール化させる形でコピーします。
|
135
|
+
なお、`rake`コマンドでテストを実行させると、自動的に`require_relative "./bin/lock_lib.rb"`により、コピーが行われます。
|
136
|
+
このあたりはトリッキーで、予定は未定ですが、今後全てモジュール化される等に統一される可能性があります。
|
137
|
+
|
42
138
|
## その他の情報
|
43
139
|
|
44
140
|
### RubyのSlackのAtCoderチャンネル
|
45
141
|
|
46
142
|
[ruby-jp](https://ruby-jp.github.io/) に"atcoder"というチャンネルがあります。
|
47
143
|
|
144
|
+
ここで、バグ報告などすると、競プロ詳しい人などが反応しやすいかもしれません。
|
145
|
+
|
48
146
|
Slackに3000人、atcoderチャンネルに250人以上の登録者がいるので、お気軽に参加してください。
|
49
147
|
|
50
148
|
### 他言語のライブラリ
|
data/README.md
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
# ac-library-rb
|
9
9
|
|
10
|
+
[](https://badge.fury.io/rb/ac-library-rb)
|
11
|
+
|
10
12
|
ac-library-rb is a ruby port of AtCoder Library (ACL).
|
11
13
|
|
12
14
|
See below for ACL.
|
@@ -25,6 +27,69 @@ Therefore, 2.7.1 is recommended and may not work with other versions.
|
|
25
27
|
|
26
28
|
Please read [index.md](https://github.com/universato/ac-library-rb/blob/master/document_en/index.md).
|
27
29
|
|
30
|
+
## How to use ac-library-rb as a Gem
|
31
|
+
|
32
|
+
We will show you how to use ac-library-rb as a gem.
|
33
|
+
## How to install
|
34
|
+
|
35
|
+
This is not limited to ac-library-rb, but I will show you how to install the two common types of gem.
|
36
|
+
|
37
|
+
- By `gem` command, `gem install ac-library-rb`.
|
38
|
+
- By using the gem bundler's commands.
|
39
|
+
|
40
|
+
#### By gem command, `gem install ac-library-rb`
|
41
|
+
|
42
|
+
Execute `gem install ac-library-rb` by using the gem command included in Ruby itself.
|
43
|
+
|
44
|
+
#### How to use the gem bundler
|
45
|
+
|
46
|
+
If you have not installed bundler, type `gem install bundler` to install it.
|
47
|
+
|
48
|
+
Next, place Gemfile under the directory where you want to use ac-library-rb.
|
49
|
+
|
50
|
+
In this Gemfile, write:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
gem "ac-library-rb".
|
54
|
+
```
|
55
|
+
|
56
|
+
Then, install ac-library-rb by using the command `budnle install`.
|
57
|
+
|
58
|
+
At this point, we need to run the Ruby file through bundler, so we use the command `bundle exec`.
|
59
|
+
|
60
|
+
`$ bundle exec ruby sample.rb`.
|
61
|
+
|
62
|
+
### How to write in Ruby files (after installation)
|
63
|
+
|
64
|
+
#### Bulk loading
|
65
|
+
|
66
|
+
To enable the ac-library-rb library to be used in bulk on Ruby files, write as follows.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
require "ac-library-rb/all"
|
70
|
+
|
71
|
+
dsu = AcLibraryRb::DSU.new
|
72
|
+
|
73
|
+
include AcLibraryRb
|
74
|
+
dsu = DSU.new
|
75
|
+
```
|
76
|
+
|
77
|
+
#### Individual loading
|
78
|
+
|
79
|
+
If you want to install only a specific library, specify the library name after `ac-library-rb/` as shown below.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
require "ac-library-rb/dsu"
|
83
|
+
dsu = AcLibraryRb::DSU.new
|
84
|
+
|
85
|
+
require "ac-library-rb/priority_queue"
|
86
|
+
pq = AcLibraryRb::PriorityQueue.new
|
87
|
+
```
|
88
|
+
|
89
|
+
Note that the gem names are separated by hyphens, but the library names in ac-library-rb are separated by underscores.
|
90
|
+
In general, underscores are recommended for Ruby library names.
|
91
|
+
However, the repository names in the original ACL are separated by a hyphen, ac-library, so ac-library-rb is also separated by a hyphen.
|
92
|
+
|
28
93
|
## Development
|
29
94
|
|
30
95
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -35,7 +100,14 @@ $ rake
|
|
35
100
|
$ ruby test/fenwick_tree_test.rb
|
36
101
|
```
|
37
102
|
|
38
|
-
# Other
|
103
|
+
# Other
|
104
|
+
|
105
|
+
## Other languages's ac-library
|
106
|
+
|
107
|
+
- [Unofficial Portings of AtCoder Library](https://docs.google.com/spreadsheets/d/19jMAqUbv98grVkLV_Lt54x5B8ILoTcvBzG8EbSvf5gY/edit#gid=0) (by [not522-san](https://github.com/not522))
|
108
|
+
|
109
|
+
|
110
|
+
## Other language Japanese version
|
39
111
|
|
40
112
|
[README 日本語バージョン(ver. Japanese)](README.ja.md)
|
41
113
|
- [ライブラリ目次: index.md](https://github.com/universato/ac-library-rb/blob/master/document_ja/index.md)
|
data/Rakefile
CHANGED
@@ -2,7 +2,8 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
require_relative "./bin/lock_lib.rb"
|
5
|
+
require_relative "./bin/lock_lib.rb" # for copy
|
6
|
+
t.warning = false
|
6
7
|
t.libs << "test"
|
7
8
|
t.libs << "lib"
|
8
9
|
t.test_files = FileList["test/**/*_test.rb"]
|
data/ac-library-rb.gemspec
CHANGED
@@ -13,17 +13,18 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = gem_description
|
14
14
|
spec.homepage = "https://github.com/universato/ac-library-rb"
|
15
15
|
spec.license = "CC0"
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/universato/ac-library-rb"
|
20
20
|
|
21
21
|
spec.add_development_dependency "minitest"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "simplecov"
|
23
24
|
|
24
25
|
# Specify which files should be added to the gem when it is released.
|
25
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
-
spec.files = Dir.chdir(File.expand_path(
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
28
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
29
|
end
|
29
30
|
spec.bindir = "exe"
|
data/bin/lock_lib.rb
CHANGED
@@ -1,27 +1,33 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
3
|
# copy libraries from `lib` to `lib_lock/ac-library` and add `module AcLibraryRb`
|
4
|
-
lib_path = File.expand_path('
|
5
|
-
lock_dir = File.expand_path('
|
4
|
+
lib_path = File.expand_path('../lib/**', __dir__)
|
5
|
+
lock_dir = File.expand_path('../lib_lock/ac-library-rb', __dir__)
|
6
6
|
Dir.glob(lib_path) do |file|
|
7
7
|
next unless FileTest.file?(file)
|
8
8
|
|
9
9
|
path = Pathname.new(lock_dir) + Pathname.new(file).basename
|
10
10
|
File.open(path, "w") do |f|
|
11
|
+
library_code = File.readlines(file).map{ |line| line == "\n" ? "\n" : ' ' + line }
|
12
|
+
|
11
13
|
f.puts "module AcLibraryRb"
|
12
|
-
f.puts
|
14
|
+
f.puts library_code
|
13
15
|
f.puts "end"
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
#
|
18
|
-
|
19
|
-
|
19
|
+
# copy library from `lib/core_ext` to `lib_lock/ac-library-rb/core_ext`
|
20
|
+
ac_library_rb_classes = %w[ModInt FenwickTree PriorityQueue]
|
21
|
+
replaces = ac_library_rb_classes.to_h{ |cls| ["#{cls}.new", "AcLibraryRb::#{cls}.new"] }
|
22
|
+
pattern = Regexp.new(replaces.keys.join('|'))
|
23
|
+
|
24
|
+
lib_path = File.expand_path('../lib/core_ext/**', __dir__)
|
25
|
+
lock_dir = File.expand_path('../lib_lock/ac-library-rb/core_ext', __dir__)
|
20
26
|
Dir.glob(lib_path) do |file|
|
21
27
|
next unless FileTest.file?(file)
|
22
28
|
|
23
29
|
path = Pathname.new(lock_dir) + Pathname.new(file).basename
|
24
30
|
File.open(path, "w") do |f|
|
25
|
-
f.puts File.readlines(file)
|
31
|
+
f.puts File.readlines(file).map{ |text| text.gsub(pattern, replaces) }
|
26
32
|
end
|
27
33
|
end
|
data/document_en/dsu.md
CHANGED
@@ -27,7 +27,7 @@ p d.size(2) # => 2
|
|
27
27
|
|
28
28
|
## Class Method
|
29
29
|
|
30
|
-
### new(n
|
30
|
+
### new(n) -> DSU
|
31
31
|
|
32
32
|
```rb
|
33
33
|
d = DSU.new(n)
|
@@ -41,7 +41,7 @@ It creates an undirected graph with `n` vertices and `0` edges.
|
|
41
41
|
|
42
42
|
**alias**
|
43
43
|
|
44
|
-
- `DSU`, `
|
44
|
+
- `DSU`, `UnionFind`
|
45
45
|
|
46
46
|
## Instance Methods
|
47
47
|
|
data/document_en/lazy_segtree.md
CHANGED
@@ -105,13 +105,29 @@ seg.range_apply(l, r, val)
|
|
105
105
|
|
106
106
|
- `O(log n)`
|
107
107
|
|
108
|
-
### max_right
|
108
|
+
### max_right(l){ } -> Integer
|
109
109
|
|
110
|
-
|
110
|
+
It applies binary search on the LazySegtree.
|
111
111
|
|
112
|
-
|
112
|
+
**Constraints**
|
113
|
+
|
114
|
+
- `0 ≦ l ≦ n`
|
115
|
+
|
116
|
+
**Complexity**
|
117
|
+
|
118
|
+
- `O(log n)`
|
119
|
+
|
120
|
+
### min_left(r){ } -> Integer
|
113
121
|
|
114
|
-
|
122
|
+
It applies binary search on the LazySegtree.
|
123
|
+
|
124
|
+
**Constraints**
|
125
|
+
|
126
|
+
- `0 ≦ r ≦ n`
|
127
|
+
|
128
|
+
**Complexity**
|
129
|
+
|
130
|
+
- `O(log n)`
|
115
131
|
|
116
132
|
## Verified
|
117
133
|
|
data/document_en/max_flow.md
CHANGED
data/document_en/segtree.md
CHANGED
@@ -4,7 +4,8 @@ Segment Tree
|
|
4
4
|
|
5
5
|
## Class Methods
|
6
6
|
|
7
|
-
### new(n, e,
|
7
|
+
### new(n, e){ |x, y| ... } -> Segtree
|
8
|
+
### new(n, op, e) -> Segtree
|
8
9
|
|
9
10
|
```rb
|
10
11
|
seg = Segtree.new(n, e) { |x, y| ... }
|
@@ -15,7 +16,9 @@ It creates an array `a` of length `n`. All the elements are initialized to `e`.
|
|
15
16
|
- `block`: returns `op(x, y)`
|
16
17
|
- `e`: identity element.
|
17
18
|
|
18
|
-
|
19
|
+
|
20
|
+
### new(ary, e){ |x, y| ... } -> Segtree
|
21
|
+
### new(ary, op, e) -> Segtree
|
19
22
|
|
20
23
|
```rb
|
21
24
|
seg = Segtree.new(ary, e) { |x, y| ... }
|
@@ -106,17 +109,47 @@ seg.max_right(l, &f)
|
|
106
109
|
|
107
110
|
It applies binary search on the segment tree.
|
108
111
|
|
112
|
+
It returns an index `r` that satisfies both of the following.
|
113
|
+
|
114
|
+
- `r = l` or `f(prod(l, r)) = true`
|
115
|
+
- `r = n` or `f(prod(l, r + 1)) = false`
|
116
|
+
|
117
|
+
|
118
|
+
**Constraints**
|
119
|
+
|
120
|
+
- `f(e) = true`
|
121
|
+
- `0 ≦ l ≦ n`
|
122
|
+
|
123
|
+
**Complexity**
|
124
|
+
|
125
|
+
- `O(log n)`
|
126
|
+
|
109
127
|
### min_left(r, &f) -> Integer
|
110
128
|
|
111
129
|
```ruby
|
112
130
|
seg.min_left(r, &f)
|
113
131
|
```
|
114
132
|
|
115
|
-
It applies binary search on the segment tree.
|
133
|
+
It applies binary search on the segment tree.
|
134
|
+
It returns an index l that satisfies both of the following.
|
135
|
+
|
136
|
+
- `l = r` or `f(prod(l, r)) = true`
|
137
|
+
- `l = 0` or `f(prod(l - 1, r)) = false`
|
138
|
+
|
139
|
+
**Constraints**
|
140
|
+
|
141
|
+
- `f(e) = true`
|
142
|
+
- `0 ≦ r ≦ n`
|
143
|
+
|
144
|
+
**Complexity**
|
145
|
+
|
146
|
+
- `O(log n)`
|
116
147
|
|
117
148
|
## Verified
|
118
149
|
|
119
150
|
- [ALPC: J \- Segment Tree](https://atcoder.jp/contests/practice2/tasks/practice2_j)
|
151
|
+
- [AC Code(884ms) max_right](https://atcoder.jp/contests/practice2/submissions/23196480)
|
152
|
+
- [AC Code(914ms) min_left](https://atcoder.jp/contests/practice2/submissions/23197311)
|
120
153
|
- [F \- Range Xor Query](https://atcoder.jp/contests/abc185/tasks/abc185_f)
|
121
154
|
- [AC Code(1538ms)](https://atcoder.jp/contests/abc185/submissions/18746817): Segtree(xor)
|
122
155
|
- [AC Code(821ms)](https://atcoder.jp/contests/abc185/submissions/18769200): FenwickTree(BIT) xor
|