Cod sursa(job #357651)
| Utilizator | Data | 19 octombrie 2009 23:43:51 | |
|---|---|---|---|
| Problema | Range minimum query | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.84 kb |
#include <fstream>
#define MAX 10000
using namespace std;
int a[MAX], n, m, i, j, b[MAX][MAX], x, y;
ifstream fin("rmq.in");
ofstream fout("rmq.out");
int main()
{
fin >> n >> m;
for ( i = 1; i <= n; i++)
fin >> a[i];
for ( i = 1; i < n; i++)
for ( j = i; j <= n; j++)
{
if ( i == j)
b[i][j] = a[i];
else
if ( a[j] < b[i][j-1])
b[i][j] = a[j];
else
b[i][j] = b[i][j-1];
}
i = 0;
while ( i < m)
{
fin >> x >> y;
fout << b[x][y] << '\n';
i++;
}
fin.close();
fout.close();
return 0;
}
