Pagini recente » Cod sursa (job #2626319) | Cod sursa (job #1676396) | Cod sursa (job #1443497) | Cod sursa (job #1573983) | Cod sursa (job #1392166)
#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
const int MAXN = 100010;
const int MAXL = 1800;
#ifndef ONLINE_JUDGE
FILE *in = fopen("rqm.in", "r");
FILE *out = fopen("rmq.out", "w");
#endif
int n, m;
int v[MAXN];
int din[MAXN][MAXL];
int rmq(int x, int y) {
int k = int(log2(y - x + 1));
return min(din[x][k], din[y - (1 << k) + 1][k]);
}
void preProcess() {
for(int i = 1; i <= n; ++i) {
din[i][0] = v[i];
}
for(int j = 1; j <= n; ++j) {
for(int i = 0; i + (1 << j) - 1 <= n; ++i) {
din[i][j] = min(din[i][j-1], din[i + (1 << (j-1))][j-1]);
}
}
}
int main() {
assert(fscanf(in, "%d%d", &n, &m));
for(int i = 1; i <= n; ++i)
assert(fscanf(in, "%d", &v[i]));
preProcess();
int a, b;
while(m--) {
assert(fscanf(in, "%d%d", &a, &b));
fprintf(out, "%d\n", rmq(a, b));
}
return 0;
}