Pagini recente » Cod sursa (job #2596495) | Cod sursa (job #37246) | Cod sursa (job #1109397) | Cod sursa (job #1052328) | Cod sursa (job #2904771)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rmq.in");
ofstream fout("rmq.out");
int rmq[200002][19], lg[200002], nrNumere, nrOperatii;
int main() {
int index1, index2, a, b, rez, aux;
fin >> nrNumere >> nrOperatii;
lg[1] = 0;
for (index1 = 2; index1 <= nrNumere; index1 += 1) {
lg[index1] = 1 + lg[index1 / 2];
}
for (index1 = 1; index1 <= nrNumere; index1 += 1) {
fin >> rmq[index1][0];
for (index2 = 1; (1 << index2) <= index1; index2 += 1)
rmq[index1][index2] = min(rmq[index1 - (1 << (index2 - 1))][index2 - 1], rmq[index1][index2 - 1]);
}
for (index1 = 1; index1 <= nrOperatii; index1 += 1) {
fin >> a >> b;
aux = lg[b - a + 1];
fout << min(rmq[a + (1 << aux) - 1][aux], rmq[b][aux]) << "\n";
}
return 0;
}