Pagini recente » Cod sursa (job #408573) | Istoria paginii runda/simoni-11-12 | Monitorul de evaluare | Cod sursa (job #1419531) | Cod sursa (job #650285)
Cod sursa(job #650285)
#include <stdio.h>
#define NMAX 100002;
long int a[NMAX][NMAX],i,j,k,st,sf,n,m;
int main(){
FILE* in=fopen("rmq.in","r");
FILE* out=fopen("rmq.out","w");
fscanf(in,"%ld ",&n);
fscanf(in,"%ld ",&m);
a[1][0]=0;
for(i=1;i<=n;i++){
fscanf(in,"%ld ",&a[1][i]);
for(j=1;j<=i;j++){
if(a[j][i-j+1]<a[j][i-j]) a[j+1][i-j]=a[j][i-j+1];
else a[j+1][i-j]=a[j][i-j];
}
}
for(k=1;k<=m;k++){
fscanf(in,"%ld ",&st);
fscanf(in,"%ld ",&sf);
fprintf(out,"%ld\n",a[sf-st+1][st]);
}
fclose(in);
fclose(out);
return 0;
}