【ST表(静态RMQ)】
// program at 2019-11-12
template <class T, int N, int M>
struct ST {
T f[N + 5][M + 1];
int log2[N];
T compare(T x, T y) {
return x < y ? x : y;
}
void init(int* a) {
log2[0] = -1;
for (int i = 1; i <= N; i++)
f[i][0] = a[i], log2[i] = log2[i >> 1] + 1;
for (int j = 1; j <= M; j++)
for (int i = 1; i + (1 << j) - 1 <= N; i++)
f[i][j] = compare(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
}
T query(int l, int r) {
int k = log2[r - l + 1];
return compare(f[l][k], f[r - (1 << k) + 1][k]);
}
};