sparse_table {
38std::vector<T> computeLogs(
conststd::vector<T>& A) {
40std::vector<T> logs(n);
42 for(
inti = 2; i < n; i++) {
43logs[i] = logs[i / 2] + 1;
56std::vector<std::vector<T> > buildTable(
conststd::vector<T>& A,
57 conststd::vector<T>& logs) {
59std::vector<std::vector<T> > table(20, std::vector<T>(n + 5, 0));
61 for(
inti = 0; i <= logs[n]; i++) {
63 for(
intj = 0; j + curLen < n; j++) {
68std::min(table[i - 1][j], table[i - 1][j + curLen / 2]);
84intgetMinimum(
intbeg,
intend,
conststd::vector<T>& logs,
85 conststd::vector<std::vector<T> >& table) {
86 intp = logs[end - beg + 1];
88 returnstd::min(table[p][beg], table[p][end - pLen + 1]);
97std::vector<int> A{1, 2, 0, 3, 9};
98std::vector<int> logs = range_queries::sparse_table::computeLogs(A);
99std::vector<std::vector<int> > table =
100range_queries::sparse_table::buildTable(A, logs);
101assert(range_queries::sparse_table::getMinimum(0, 0, logs, table) == 1);
102assert(range_queries::sparse_table::getMinimum(0, 4, logs, table) == 0);
103assert(range_queries::sparse_table::getMinimum(2, 4, logs, table) == 0);
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4