Pagini recente » Cod sursa (job #2916986) | Cod sursa (job #1978949) | Cod sursa (job #749978) | Cod sursa (job #2490842) | Cod sursa (job #1414603)
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fs first
#define sc second
#define pob pop_back
#define pub push_back
#define eps 1E-7
#define sz(a) a.size()
#define count_one __builtin_popcount;
#define count_onell __builtin_popcountll;
#define fastIO ios_base::sync_with_stdio(false)
#define PI (acos(-1.0))
#define linf (1LL<<62)//>4e18
#define inf (0x7f7f7f7f)//>2e9
#ifndef ONLINE_JUDGE
ifstream fin("rmq.in");
ofstream fout("rmq.out");
#endif
const int MAXN = 100010;
const int LOGN = 20;
int n, m;
int rmq[MAXN][LOGN];
void read() {
fin >> n >> m;
for(int i = 0; i < n; ++i) {
fin >> rmq[i][0];
}
for(int j = 1; (1 << j) <= n; ++j) {
for(int i = 0; i + (1 << j) - 1 < n; ++i) {
rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
}
}
int a, b, k;
while(m--) {
fin >> a >> b;
a--; b--;
k = int(log2(b - a + 1));
fout << min(rmq[a][k], rmq[b - (1 << k) + 1][k]) << "\n";
}
}
int main() {
read();
return 0;
}