NgLib::DualSegTree(T)
Inherits Indexable::Mutable < Indexable < Enumerable < Iterable < Indexable < Enumerable < Iterable < Reference < Object
区間作用・$1$ 点取得ができるセグメント木です。
作用素 $f$ は、要素 $x$ と同じ型である必要があります。
Constructors
作用素を $f$ とした、$i$ 番目の要素が values[i] の双対セグメント木を作ります。
seg = NgLib::DualSegTree(Int32).new([*(1..5)]) { |f, x| x + f }
seg # => [1, 2, 3, 4, 5]
Class methods
Instance methods
#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]
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.