Pagini recente » Cod sursa (job #743894) | Cod sursa (job #282114) | Cod sursa (job #3197339) | Cod sursa (job #3273928) | Cod sursa (job #2904720)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rmq.in");
ofstream fout("rmq.out");
int rmq[18][200002], numere[200002];
int main() {
int nrNumere, nrOperatii, index1, index2, a, b;
fin >> nrNumere >> nrOperatii;
for (index1 = 0; index1 < nrNumere; index1 += 1) {
fin >> numere[index1];
}
for (index1 = 0; index1 < nrNumere; index1++)
rmq[index1][index1] = index1;
for (index1 = 0; index1 < nrNumere; index1++) {
for (index2 = index1 + 1; index2 < nrNumere; index2++)
if (numere[rmq[index1][index2 - 1]] < numere[index2])
rmq[index1][index2] = rmq[index1][index2 - 1];
else
rmq[index1][index2] = index2;
}
for (index1 = 0; index1 < nrOperatii; index1 += 1) {
fin >> a >> b;
a -= 1;
b -= 1;
fout << numere[rmq[a][b]] << "\n";
}
return 0;
}