Pagini recente » Cod sursa (job #1047059) | Cod sursa (job #2798454) | Cod sursa (job #1556177) | Cod sursa (job #1480172) | Cod sursa (job #2904719)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rmq.in");
ofstream fout("rmq.out");
int rmq[400][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;
}