This documentation is automatically generated by online-judge-tools/verification-helper
#include "DS/Sparse_table.hpp"
Range Minimum Queries on an array. Returns min(V[a], V[a + 1], … V[b - 1]) in constant time. Also work for max queries
#pragma once
template<class T>
struct sparsetable {
vector<vector<T>> jmp;
sparsetable(const vector<T>& V) : jmp(1, V) {
for (int pw = 1, k = 1; pw * 2 <= V.size(); pw *= 2, ++k) {
jmp.emplace_back(V.size() - pw * 2 + 1);
rep(j,jmp[k].size())
jmp[k][j] = min(jmp[k - 1][j], jmp[k - 1][j + pw]);
}
}
T query(int a, int b) {
assert(a < b); // or return inf if a == b
int dep = 31 - __builtin_clz(b - a);
return min(jmp[dep][a], jmp[dep][b - (1 << dep)]);
}
};
#line 2 "DS/Sparse_table.hpp"
template<class T>
struct sparsetable {
vector<vector<T>> jmp;
sparsetable(const vector<T>& V) : jmp(1, V) {
for (int pw = 1, k = 1; pw * 2 <= V.size(); pw *= 2, ++k) {
jmp.emplace_back(V.size() - pw * 2 + 1);
rep(j,jmp[k].size())
jmp[k][j] = min(jmp[k - 1][j], jmp[k - 1][j + pw]);
}
}
T query(int a, int b) {
assert(a < b); // or return inf if a == b
int dep = 31 - __builtin_clz(b - a);
return min(jmp[dep][a], jmp[dep][b - (1 << dep)]);
}
};