Documentation
¶
Index ¶
- Constants
- func ForEach[V any](arr []V, operator func(v V, i int) bool)
- func ForEachReverse[V any](arr []V, operator func(v V, i int) bool)
- func NewBool2d(a, b int, value bool) [][]bool
- func NewFloat2d(a, b int, value float64) [][]float64
- func NewInt2d(a, b, value int) [][]int
- func NewInt3d(a, b, c, value int) [][][]int
- func Rotate[V any](arr [][]V) [][]V
- func Unique[V constraints.Ordered](arr []V) []V
- type BitSet
- type Counter
- type Deque
- func (queue *Deque[T]) Add(value T)
- func (queue *Deque[T]) AddFirst(value T)
- func (queue *Deque[T]) AddLast(value T)
- func (queue *Deque[T]) Count() int
- func (queue *Deque[T]) First() T
- func (queue *Deque[T]) Get() T
- func (queue *Deque[T]) HasElements() bool
- func (queue *Deque[T]) IsEmpty() bool
- func (queue *Deque[T]) Last() T
- func (queue *Deque[T]) Peek() T
- func (queue *Deque[T]) Pop() T
- func (queue *Deque[T]) Push(value T)
- func (queue *Deque[T]) Remove() T
- func (queue *Deque[T]) RemoveFirst() T
- func (queue *Deque[T]) RemoveLast() T
- type DijkstraResult
- type DualSegmentTree
- type DynamicSegmentTree
- type Edge
- type Graph
- func (g *Graph) AddDirectedEdge(u, v int)
- func (g *Graph) AddDirectedWeightedEdge(u, v, w int)
- func (g *Graph) AddEdge(u, v int)
- func (g *Graph) AddEdge1(u, v int)
- func (g *Graph) AddWeightedEdge(u, v, w int)
- func (g *Graph) BellmanFord(s, t int)
- func (g *Graph) CountNodes() int
- func (g *Graph) Dijkstra(s int) *DijkstraResult
- func (g *Graph) Lca(root int) *Lca
- func (g *Graph) MaxFlow(s, t int) int
- func (g *Graph) Scc() Scc
- func (g *Graph) WarshallFloyd() [][]int
- type Int2d
- type Int4d
- type IntLazySegmentTree
- type LargeBitSet
- type LargeBitSetNode
- type LazySegmentTree
- type Lca
- type LinkedList
- func (list *LinkedList[V]) Add(value V) *LinkedListNode[V]
- func (list *LinkedList[V]) AddBack(value V) *LinkedListNode[V]
- func (list *LinkedList[V]) AddFront(value V) *LinkedListNode[V]
- func (list *LinkedList[V]) Back() V
- func (list *LinkedList[V]) Front() V
- func (list *LinkedList[V]) Len() int
- func (list *LinkedList[V]) RemoveBack() V
- func (list *LinkedList[V]) RemoveFront() V
- func (list *LinkedList[V]) ToArray() []V
- type LinkedListNode
- type Map
- type PriorityQueue
- type RedBlackTree
- func (tree *RedBlackTree[K, V]) Ceiling(key K) (*K, *V)
- func (tree *RedBlackTree[K, V]) Empty() bool
- func (tree *RedBlackTree[K, V]) Floor(key K) (*K, *V)
- func (tree *RedBlackTree[K, V]) Get(key K) *V
- func (tree *RedBlackTree[K, V]) HasEntry() bool
- func (tree *RedBlackTree[K, V]) Left() (*K, *V)
- func (tree *RedBlackTree[K, V]) Put(key K, value V)
- func (tree *RedBlackTree[K, V]) Remove(key K)
- func (tree *RedBlackTree[K, V]) Size() int
- func (tree *RedBlackTree[K, V]) String() string
- type Scc
- type SegmentTree
- type Stack
- type SuccinctIndexableDictionary
- type Trie
- type TrieNode
- type UnionFind
- type WaveletMatrix
- func (wm *WaveletMatrix) FreqGreaterThan(left, right int, maxVal int) int
- func (wm *WaveletMatrix) FreqLessThan(left, right int, minVal int) int
- func (wm *WaveletMatrix) Get(index int) int
- func (wm *WaveletMatrix) QuantileRange(left, right, k int) int
- func (wm *WaveletMatrix) RangeFreq(left, right int, minVal, maxVal int) int
- func (wm *WaveletMatrix) Rank(index, value int) int
- func (wm *WaveletMatrix) Select(value, rank int) int
- type WeightedUnionFind
Constants ¶
const ( Head balanceOrder = iota Tail )
const LEVEL_L = 65536
const LEVEL_S = 256
Variables ¶
This section is empty.
Functions ¶
func ForEachReverse ¶
ForEachReverseは配列の各要素に対して逆順にoperatorを適用します。 operatorがfalseを返した場合、処理を終了します。
func NewFloat2d ¶
Types ¶
type Deque ¶
type Deque[T any] struct { // contains filtered or unexported fields }
DequeはStackを2つ使用したDequeの実装です。
func (*Deque[T]) HasElements ¶
HasElementsはQueue.HasElementsの実装
func (*Deque[T]) RemoveFirst ¶
func (queue *Deque[T]) RemoveFirst() T
func (*Deque[T]) RemoveLast ¶
func (queue *Deque[T]) RemoveLast() T
type DijkstraResult ¶
type DualSegmentTree ¶
type DualSegmentTree[V, X, F any] struct { Init func(n int) *DualSegmentTree[V, X, F] Update func(l, r int, value F) Query func(i int) V }
Vは扱う値、Xは保持する値、Fは適用する値
func NewDualSegmentTree ¶
func NewDualSegmentTree[V, X, F any]( mapping func(x *X, v *V), composition func(f *F, x *X), e func() V, id func() X, ) *DualSegmentTree[V, X, F]
type DynamicSegmentTree ¶
type DynamicSegmentTree[V any] struct { // Initは[0, n)のsegment treeを初期化します。 // 各要素の値は単位元となります。 Init func(n int) *DynamicSegmentTree[V] // Getはi(0-based)番目の値を返します。 Get func(i int) *V // Updateはi(0-based)番目の値をvalueに更新します。 Update func(i int, value *V) // Queryは[l, r) (0-based)の計算値を返します。 Query func(l, r int) *V }
func NewDynamicSegmentTree ¶
func NewDynamicSegmentTree[V any]( e func() *V, calc func(a, b, ab *V), ) *DynamicSegmentTree[V]
type Graph ¶
Graph はグラフを表現する構造です
func (*Graph) AddDirectedEdge ¶
AddDirectedEdgeはuからvへ重み1の有向辺を追加します。
func (*Graph) AddDirectedWeightedEdge ¶
AddDirectedWeightedEdgeはuからvへ重みwの有向辺を追加します。
func (*Graph) AddWeightedEdge ¶
AddWeightedEdge はuからvへ重みwの無向辺を追加します。
func (*Graph) Dijkstra ¶
func (g *Graph) Dijkstra(s int) *DijkstraResult
Dijkstra はsから各頂点への最短距離を返します。 重みが負の辺があるときには使用できません。 計算量: |V| + |E|log|V|
func (*Graph) WarshallFloyd ¶
WarshallFloyd は全点対の最短ルートを返します。
type IntLazySegmentTree ¶
type IntLazySegmentTree struct { // Initは長さnの配列として初期化します Init func(n int) *IntLazySegmentTree // InitByArrayはarrとして初期化します。 InitByArray func(arr []int) *IntLazySegmentTree // Updateは[l, r)をfで更新します。 Update func(l, r int, f int) // Queryは[l, r)の値を返します。 Query func(l, r int) int }
type LargeBitSet ¶
type LargeBitSet struct { // Addはこの集合にvを追加します。 Add func(v int) // Hasはこの集合にvが含まれるかどうかを判断します。 Has func(v int) bool // Removeはこの集合からvを削除します。 Remove func(v int) // Beforeはこの集合に含まれるv未満の要素のうち、最大の要素を返します。 // 存在しない場合はnilを返します。 Before func(v int) *int // Afterはこの集合に含まれるvを超える要素のうち、最小の要素を返します。 // 存在しない場合はnilを返します。 After func(v int) *int // contains filtered or unexported fields }
巨大サイズの非負整数の集合を管理します。
func NewLargeBitSet ¶
func NewLargeBitSet() *LargeBitSet
type LargeBitSetNode ¶
type LargeBitSetNode struct {
// contains filtered or unexported fields
}
func (*LargeBitSetNode) Index ¶
func (n *LargeBitSetNode) Index(v int) int
Indexはこのノードが持つ子要素のうち、vに対応するインデックスを返します。
func (*LargeBitSetNode) String ¶
func (n *LargeBitSetNode) String() string
type LazySegmentTree ¶
type LazySegmentTree[V, F any] struct { // Initは長さnの配列として初期化します Init func(n int) *LazySegmentTree[V, F] // InitByArrayはarrとして初期化します。 InitByArray func(arr []V) *LazySegmentTree[V, F] // Updateは[l, r)をfで更新します。 Update func(l, r int, f F) // Queryは[l, r)の値を返します。 Query func(l, r int) V }
func NewLazySegmentTree ¶
func NewLazySegmentTree[V, F any]( operate func(a, b, ab *V), mapping func(f *F, x *V), composition func(f, g, fg *F), e func() V, id func() F, ) *LazySegmentTree[V, F]
NewLazySegmentTreeは遅延評価セグメントツリーの実装を返します。 Vは扱うモノイドの型、Fはモノイドに適用する写像をあらわします。
例えば range add range max queryの場合、以下のようになります。
st := NewLazySegmentTree[int, int](
max, func(f, x int) int { return f + x }, func(f, g int) int { return f + g }, func() int { return 0 }, func() int { return 0 },
)
type LinkedList ¶
type LinkedList[V any] struct { // contains filtered or unexported fields }
func NewLinkedList ¶
func NewLinkedList[V any]() *LinkedList[V]
func (*LinkedList[V]) Add ¶
func (list *LinkedList[V]) Add(value V) *LinkedListNode[V]
func (*LinkedList[V]) AddBack ¶
func (list *LinkedList[V]) AddBack(value V) *LinkedListNode[V]
func (*LinkedList[V]) AddFront ¶
func (list *LinkedList[V]) AddFront(value V) *LinkedListNode[V]
func (*LinkedList[V]) Back ¶
func (list *LinkedList[V]) Back() V
func (*LinkedList[V]) Front ¶
func (list *LinkedList[V]) Front() V
func (*LinkedList[V]) Len ¶
func (list *LinkedList[V]) Len() int
func (*LinkedList[V]) RemoveBack ¶
func (list *LinkedList[V]) RemoveBack() V
func (*LinkedList[V]) RemoveFront ¶
func (list *LinkedList[V]) RemoveFront() V
func (*LinkedList[V]) ToArray ¶
func (list *LinkedList[V]) ToArray() []V
type LinkedListNode ¶
type LinkedListNode[V any] struct { // contains filtered or unexported fields }
func (*LinkedListNode[V]) AddAfter ¶
func (node *LinkedListNode[V]) AddAfter(value V) *LinkedListNode[V]
func (*LinkedListNode[V]) AddBefore ¶
func (node *LinkedListNode[V]) AddBefore(value V) *LinkedListNode[V]
func (*LinkedListNode[V]) Remove ¶
func (node *LinkedListNode[V]) Remove() V
type Map ¶
type PriorityQueue ¶
type PriorityQueue[T any] struct { // Pushは優先度付きキューに要素を一つ追加します。 Push func(value T) // Popは優先度付きキューから要素を一つ取り出します。 Pop func() T // Peekは優先度つきキューの先頭要素を返します。 Peek func() T // IsEmptyは優先度付きキューが空かどうかを判断します。 IsEmpty func() bool // HasElementsはこの優先度付きキューが要素を持つかどうかを判断します。 HasElements func() bool // Countはこの優先度付きキューがもつ要素の数を返します。 Count func() int }
PriorityQueue は優先度付きキューを表す
func NewPriorityQueue ¶
func NewPriorityQueue[T any](prior func(a, b T) bool) *PriorityQueue[T]
NewPriorityQueueはpriorで優先度が決まる空の優先度付きキューを返します。
type RedBlackTree ¶
func NewRedBlackTree ¶
func NewRedBlackTree[K any, V any](comparator func(a, b K) int) *RedBlackTree[K, V]
func (*RedBlackTree[K, V]) Ceiling ¶
func (tree *RedBlackTree[K, V]) Ceiling(key K) (*K, *V)
func (*RedBlackTree[K, V]) Empty ¶
func (tree *RedBlackTree[K, V]) Empty() bool
func (*RedBlackTree[K, V]) Floor ¶
func (tree *RedBlackTree[K, V]) Floor(key K) (*K, *V)
func (*RedBlackTree[K, V]) Get ¶
func (tree *RedBlackTree[K, V]) Get(key K) *V
func (*RedBlackTree[K, V]) HasEntry ¶
func (tree *RedBlackTree[K, V]) HasEntry() bool
func (*RedBlackTree[K, V]) Left ¶
func (tree *RedBlackTree[K, V]) Left() (*K, *V)
func (*RedBlackTree[K, V]) Put ¶
func (tree *RedBlackTree[K, V]) Put(key K, value V)
func (*RedBlackTree[K, V]) Remove ¶
func (tree *RedBlackTree[K, V]) Remove(key K)
func (*RedBlackTree[K, V]) Size ¶
func (tree *RedBlackTree[K, V]) Size() int
func (*RedBlackTree[K, V]) String ¶
func (tree *RedBlackTree[K, V]) String() string
type Scc ¶
type Scc struct { // nは強連結成分分解後の頂点数 Size int // Graphは強連結成分分解後のグラフ Graph [][]int // Componentsは強連結成分分解後の頂点(0-indexed)と、その頂点に対応する、もとのグラフの頂点(0-indexed)の配列 Components [][]int // Nodesはもとのグラフの頂点(0-indexed)と、対応する新しい頂点(0-indexed) Nodes map[int]int }
Sccは強連結成分分解の結果を表します。
type SegmentTree ¶
type SegmentTree[V any] struct { // Initは[0, n)のsegment treeを初期化します。 // 各要素の値は単位元となります。 // tested: // // https://atcoder.jp/contests/abl/tasks/abl_d Init func(n int) *SegmentTree[V] // InitAsArrayはvalsで配列を初期化します。 // 区間の長さはlen(vals)になります。 // tested: // // https://judge.yosupo.jp/problem/staticrmq InitAsArray func(arr []V) *SegmentTree[V] // Updateはi(0-based)番目の値をvalueに更新します。 // tested: // // https://atcoder.jp/contests/abl/tasks/abl_d Update func(i int, value V) // Queryは[l, r) (0-based)の計算値を返します。 // tested: // // https://atcoder.jp/contests/abl/tasks/abl_d Query func(l, r int) V // Getはi(0-based)番目の値を返します。 Get func(i int) V }
func NewSegmentTree ¶
func NewSegmentTree[V any]( e func() V, calc func(a, b, ab *V), ) *SegmentTree[V]
NewSegmentTreeは区間和を扱うSegmentTreeを返します。 tested:
https://atcoder.jp/contests/abl/tasks/abl_d
type Stack ¶
type Stack[T any] struct { // PushはこのStackの末尾に要素を追加します。 Push func(value T) // PopはこのStackの末尾から要素を取り出し、その要素を返します。 Pop func() T // PeekはこのStackの末尾の要素を返します。 // 末尾の要素は削除されません。 Peek func() T // CountはこのStackに保存されている要素の数を返します。 Count func() int // HasElementsはこのStackに要素が設定されているかを判断します。 HasElements func() bool // IsEmptyはこのStackが空かどうかを判断します。 IsEmpty func() bool // contains filtered or unexported fields }
Stackは先入れ後出しのデータ構造を表現します。
type SuccinctIndexableDictionary ¶
type SuccinctIndexableDictionary struct {
// contains filtered or unexported fields
}
完備辞書
func NewSuccinctIndexableDictionary ¶
func NewSuccinctIndexableDictionary(size int) *SuccinctIndexableDictionary
func (*SuccinctIndexableDictionary) Build ¶
func (s *SuccinctIndexableDictionary) Build()
func (*SuccinctIndexableDictionary) Get ¶
func (s *SuccinctIndexableDictionary) Get(i int) uint
func (*SuccinctIndexableDictionary) Rank ¶
func (s *SuccinctIndexableDictionary) Rank(i int, bit uint) int
Rankは[0, i)に含まれるbitの数を返す。
func (*SuccinctIndexableDictionary) Select ¶
func (s *SuccinctIndexableDictionary) Select(bit uint, rank int) int
rank番目のbitの位置 + 1を返す。rankは1-origin。
func (*SuccinctIndexableDictionary) Set ¶
func (s *SuccinctIndexableDictionary) Set(i int, bit uint)
Setはi番目のビットをbitにします。
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
func (*Trie) IsPrefixOf ¶
IsPrefixOfは、このTrieがもつ文字列のいずれかがsのprefixであるかどうかを返します。
func (*Trie) RemovePrefix ¶
RemovePrefixは、sをprefixとしてもつ文字列を全て削除し、その数を返す
type UnionFind ¶
type UnionFind struct {
// contains filtered or unexported fields
}
UnionFind : UnionFind構造を保持する構造体
type WaveletMatrix ¶
type WaveletMatrix struct {
// contains filtered or unexported fields
}
WaveletMatrixは、整数の配列に対して以下の操作を効率的に行うデータ構造です。
func NewWaveletMatrix ¶
func NewWaveletMatrix(data []int) *WaveletMatrix
func (*WaveletMatrix) FreqGreaterThan ¶
func (wm *WaveletMatrix) FreqGreaterThan(left, right int, maxVal int) int
FreqGreaterThanは、[left, right)の範囲に含まれるmaxValより大きい値の個数を返します。
func (*WaveletMatrix) FreqLessThan ¶
func (wm *WaveletMatrix) FreqLessThan(left, right int, minVal int) int
FreqLessThanは、[left, right)の範囲に含まれるminValより小さい値の個数を返します。
func (*WaveletMatrix) QuantileRange ¶
func (wm *WaveletMatrix) QuantileRange(left, right, k int) int
QuantileRangeは、[left, right)の範囲に含まれるk(0-origin)番目の値を返します。
func (*WaveletMatrix) RangeFreq ¶
func (wm *WaveletMatrix) RangeFreq(left, right int, minVal, maxVal int) int
RangeFreqは、[left, right)の範囲に含まれる[minVal, maxVal)の個数を返します。
func (*WaveletMatrix) Rank ¶
func (wm *WaveletMatrix) Rank(index, value int) int
Rankはwm[0:index)の中にvalueがいくつあるかを返します。
func (*WaveletMatrix) Select ¶
func (wm *WaveletMatrix) Select(value, rank int) int
Selectはi番目のcの位置+1を返す。rankは1-origin。
type WeightedUnionFind ¶
type WeightedUnionFind struct {
// contains filtered or unexported fields
}
重み付きUnion-Findは集合と、各ノードがルートからどれくらい距離があるかを管理します。
func NewWeightedUnionFind ¶
func NewWeightedUnionFind(n int) *WeightedUnionFind
NewWeightedUnionFindは重み付きUnion-Findの実装を返します。
func (*WeightedUnionFind) Diff ¶
func (uf *WeightedUnionFind) Diff(x, y int) int
weight[y]-weight[x]を返します。
func (*WeightedUnionFind) IsSame ¶
func (uf *WeightedUnionFind) IsSame(x, y int) bool
xとyが同じ集合にいるかを判断します。
func (*WeightedUnionFind) Merge ¶
func (uf *WeightedUnionFind) Merge(x, y, w int) bool
weight[y]-weight[x] = wとなるようにマージします
Source Files
¶
- arrays.go
- bitset.go
- counter.go
- deque.go
- dual-segment-tree.go
- dynamic-segment-tree.go
- graph.go
- int-lazy-segment-tree.go
- large-bit-set.go
- lazy-segment-tree.go
- linked-list.go
- map.go
- priority-queue.go
- red-black-tree.go
- segment-tree.go
- stack.go
- succinct-indexable-dictionary.go
- trie.go
- union-find.go
- wavelet-matrix.go
- weighted-union-find.go