This documentation is automatically generated by competitive-verifier/competitive-verifier
#define PROBLEM "https://judge.yosupo.jp/problem/staticrmq"
#include <bits/stdc++.h>
using namespace std;
#include "../../../../data-structure/others/SparseTable.hpp"
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q;
auto f = [=](const int &x, const int &y) { return min(x, y); };
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
SparseTable<int, f> s(a);
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
cout << s.query(l, r) << "\n";
}
}
#line 1 "verify/LibraryChecker/data-structure/others/StaticRMQ.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/staticrmq"
#include <bits/stdc++.h>
using namespace std;
#line 1 "data-structure/others/SparseTable.hpp"
template <class T, auto f>
class SparseTable {
private:
vector<vector<T>> st;
vector<int> lookup;
public:
SparseTable() {}
SparseTable(const vector<T> &v) {
const int n = (int)v.size();
const int b = 32 - __builtin_clz(n);
st.assign(b, vector<T>(n));
for (int i = 0; i < v.size(); i++) {
st[0][i] = v[i];
}
for (int i = 1; i < b; i++) {
for (int j = 0; j + (1 << i) <= n; j++) {
st[i][j] = f(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
}
lookup.resize(v.size() + 1);
for (int i = 2; i < lookup.size(); i++) {
lookup[i] = lookup[i >> 1] + 1;
}
}
inline T query(int l, int r) const {
int b = lookup[r - l];
return f(st[b][l], st[b][r - (1 << b)]);
}
};
#line 5 "verify/LibraryChecker/data-structure/others/StaticRMQ.test.cpp"
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q;
auto f = [=](const int &x, const int &y) { return min(x, y); };
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
SparseTable<int, f> s(a);
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
cout << s.query(l, r) << "\n";
}
}