This documentation is automatically generated by online-judge-tools/verification-helper
#include "Src/DataStructure/SparseTable/SparseTable.hpp"
ドキュメントを書く気力が行方不明!
等冪則を持つ演算、忘れがち(Disjoint Sparse Tableを書きましょう….)
#pragma once
#include "../../Template/TypeAlias.hpp"
#include <vector>
#include <cassert>
#include <ostream>
namespace zawa {
template <class Structure>
class SparseTable {
private:
using Value = typename Structure::Element;
std::vector<u32> L;
std::vector<std::vector<Value>> dat;
public:
SparseTable() : L{}, dat{} {}
SparseTable(const std::vector<Value>& a) : L(a.size() + 1), dat{} {
for (u32 i{1} ; i < L.size() ; i++) {
L[i] = L[i - 1] + (i >> (L[i - 1] + 1));
}
dat.resize(L.back() + 1);
dat[0] = a;
for (u32 i{1}, len{2} ; i < dat.size() ; i++, len <<= 1) {
dat[i] = dat[i - 1];
for (u32 j{} ; j + len - 1 < dat[i].size() ; j++) {
dat[i][j] = Structure::operation(dat[i - 1][j], dat[i - 1][j + (len >> 1)]);
}
}
}
Value product(u32 l, u32 r) const {
assert(l <= r);
assert(l < dat[0].size());
assert(r <= dat[0].size());
u32 now{L[r - l]};
return Structure::operation(dat[now][l], dat[now][r - (1 << now)]);
}
friend std::ostream& operator<<(std::ostream& os, const SparseTable<Structure>& spt) {
for (u32 i{}, len{1} ; i < spt.dat.size() ; i++, len <<= 1) {
os << "length = " << len << '\n';
for (u32 j{} ; j + len - 1 < spt.dat[i].size() ; j++) {
os << spt.dat[i][j] << (j + len == spt.dat[i].size() ? '\n' : ' ');
}
}
return os;
}
};
} // namespace zawa
#line 2 "Src/DataStructure/SparseTable/SparseTable.hpp"
#line 2 "Src/Template/TypeAlias.hpp"
#include <cstdint>
#include <cstddef>
namespace zawa {
using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;
using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;
} // namespace zawa
#line 4 "Src/DataStructure/SparseTable/SparseTable.hpp"
#include <vector>
#include <cassert>
#include <ostream>
namespace zawa {
template <class Structure>
class SparseTable {
private:
using Value = typename Structure::Element;
std::vector<u32> L;
std::vector<std::vector<Value>> dat;
public:
SparseTable() : L{}, dat{} {}
SparseTable(const std::vector<Value>& a) : L(a.size() + 1), dat{} {
for (u32 i{1} ; i < L.size() ; i++) {
L[i] = L[i - 1] + (i >> (L[i - 1] + 1));
}
dat.resize(L.back() + 1);
dat[0] = a;
for (u32 i{1}, len{2} ; i < dat.size() ; i++, len <<= 1) {
dat[i] = dat[i - 1];
for (u32 j{} ; j + len - 1 < dat[i].size() ; j++) {
dat[i][j] = Structure::operation(dat[i - 1][j], dat[i - 1][j + (len >> 1)]);
}
}
}
Value product(u32 l, u32 r) const {
assert(l <= r);
assert(l < dat[0].size());
assert(r <= dat[0].size());
u32 now{L[r - l]};
return Structure::operation(dat[now][l], dat[now][r - (1 << now)]);
}
friend std::ostream& operator<<(std::ostream& os, const SparseTable<Structure>& spt) {
for (u32 i{}, len{1} ; i < spt.dat.size() ; i++, len <<= 1) {
os << "length = " << len << '\n';
for (u32 j{} ; j + len - 1 < spt.dat[i].size() ; j++) {
os << spt.dat[i][j] << (j + len == spt.dat[i].size() ? '\n' : ' ');
}
}
return os;
}
};
} // namespace zawa