Sparse Table
(datastructure/sparsetable.hpp)
概要
静的な数列に対する区間取得クエリを定数時間で答えられるデータ構造.
渡す二項演算$f$は結合律と冪等律を満たす必要がある.
- 結合律 : $f(f(x, y), z) = f(x, f(y, z))$
- 冪等律 : $f(x, x) = x$
計算量
- 構築 : $O(n\log n)$
- 区間取得 : $O(1)$
使用例
-
SparseTable<int> st(v, [](int a, int b){ return min(a, b); })
: 区間最小クエリを処理するSparse Tableを構築.
-
st.query(l, r)
: 半開区間$[l, r)$の区間取得クエリ.
Verified with
Code
Back to top page