Cod sursa(job #1887424)
| Utilizator | Data | 21 februarie 2017 16:30:41 | |
|---|---|---|---|
| Problema | Range minimum query | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rmq.in");
ofstream fout("rmq.out");
int N,M,A[10001][10001],arr[100001];
void precompute(){
for (int i=1;i<=N;i++){
for (int j=i+1;j<=N;j++){
A[i][j]=min(A[j][j],A[i][j-1]);
}
}
}
int main(){
fin >>N>>M;
for (int i=0;i<=1000;i++)
for (int j=0;j<=1000;j++) A[i][j]=1e9;//cout <<A[i][j]<<" \n"[j==N];
for (int i=1;i<=N;i++) fin >>A[i][i];
precompute();
for (int i=1;i<=M;i++){
int x,y;
fin >>x>>y;
fout <<A[x][y]<<"\n";
}
return 0;
}
