class NgLib::DualSegTree(T)
- NgLib::DualSegTree(T)
- Reference
- Object
Overview
区間作用・$1$ 点取得ができるセグメント木です。
作用素 $f$ は、要素 $x$ と同じ型である必要があります。
Included Modules
- Indexable(T)
- Indexable::Mutable(T)
Defined in:
nglib/data_structure/dual_seg_tree.crConstructors
-
.new(values : Array(T), &application : T, T -> T)
作用素を $f$ とした、$i$ 番目の要素が
values[i]の双対セグメント木を作ります。 -
.new(size : Int, &application : T, T -> T)
作用素を $f$ とした、要素数 $n$ の双対セグメント木を作ります。
Class Method Summary
-
.range_add(values : Array(T))
作用素 $f(x) = x + f$ とした双対セグメント木を作ります。
-
.range_add(size : Int)
作用素 $f(x) = x + f$ とした双対セグメント木を作ります。
-
.range_chmax(values : Array(T))
作用素 $f(x) = \max(f, x)$ とした双対セグメント木を作ります。
-
.range_chmax(size : Int)
作用素 $f(x) = \max(f, x)$ とした双対セグメント木を作ります。
-
.range_chmin(values : Array(T))
作用素 $f(x) = \min(f, x)$ とした双対セグメント木を作ります。
-
.range_chmin(size : Int)
作用素 $f(x) = \min(f, x)$ とした双対セグメント木を作ります。
-
.range_update(values : Array(T))
作用素 $f(x) = f$ とした双対セグメント木を作ります。
-
.range_update(size : Int)
作用素 $f(x) = f$ とした双対セグメント木を作ります。
Instance Method Summary
-
#[]=(start : Int, count : Int, applicator : T)
#applyへのエイリアスです。 -
#[]=(range : Range(Int | Nil, Int | Nil), applicator : T)
#applyへのエイリアスです。 -
#apply(start : Int, count : Int, application : T)
start番目からcount個までの各要素にapplicatorを作用させます。 -
#apply(range : Range(Int | Nil, Int | Nil), applicator : T)
rangeの表す区間にapplicatorを作用させます。 -
#apply_all(applicator : T)
すべての要素に
applicationを作用させます。 -
#size : Int32
Returns the number of elements in this container.
-
#to_s(io : IO)
Appends a short String representation of this object which includes its class name and its object address.
-
#unsafe_fetch(index : Int)
Returns the element at the given index, without doing any bounds check.
-
#unsafe_put(index : Int, value : T)
Sets the element at the given index to value, without doing any bounds check.
Constructor Detail
作用素を $f$ とした、$i$ 番目の要素が values[i] の双対セグメント木を作ります。
seg = NgLib::DualSegTree(Int32).new([*(1..5)]) { |f, x| x + f }
seg # => [1, 2, 3, 4, 5]
作用素を $f$ とした、要素数 $n$ の双対セグメント木を作ります。
各要素は単位元を表す nil で初期化されます。
seg = NgLib::DualSegTree(Int32).new(5) { |f, x| x + f }
seg # => [nil, nil, nil, nil, nil]
Class Method Detail
Instance Method Detail
#apply へのエイリアスです。
seg = NgLib::DualSegTree(Int32).new([*(1..5)]) { |f, x| x + f }
seg # => [1, 2, 3, 4, 5]
seg[0, 2] = 10
seg # => [11, 12, 3, 4, 5]
#apply へのエイリアスです。
seg = NgLib::DualSegTree(Int32).new([*(1..5)]) { |f, x| x + f }
seg # => [1, 2, 3, 4, 5]
seg[0...2] = 10
seg # => [11, 12, 3, 4, 5]
start 番目から count 個までの各要素に applicator を作用させます。
seg = NgLib::DualSegTree(Int32).new([*(1..5)]) { |f, x| x + f }
seg # => [1, 2, 3, 4, 5]
seg.apply(0, 2, 10)
seg # => [11, 12, 3, 4, 5]
range の表す区間に applicator を作用させます。
seg = NgLib::DualSegTree(Int32).new([*(1..5)]) { |f, x| x + f }
seg # => [1, 2, 3, 4, 5]
seg.apply(0...2, 10)
seg # => [11, 12, 3, 4, 5]
すべての要素に application を作用させます。
seg = NgLib::DualSegTree(Int32).new([*(1..5)]) { |f, x| x + f }
seg # => [1, 2, 3, 4, 5]
seg.all_apply(10)
seg # => [11, 12, 13, 14, 15]
Returns the number of elements in this container.
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Returns the element at the given index, without doing any bounds check.
Indexable makes sure to invoke this method with index in 0...size,
so converting negative indices to positive ones is not needed here.
Clients never invoke this method directly. Instead, they access
elements with #[](index) and #[]?(index).
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.
Sets the element at the given index to value, without doing any bounds check.
Indexable::Mutable makes sure to invoke this method with index in
0...size, so converting negative indices to positive ones is not needed
here.
Clients never invoke this method directly. Instead, they modify elements
with #[]=(index, value).
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.