Pagini recente » Cod sursa (job #3178831) | Cod sursa (job #2343652) | Cod sursa (job #1701522) | Cod sursa (job #1692143) | Cod sursa (job #3155168)
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
int sp[100000][18];
int querty(int i,int j){
int len=j-i+1;
int k=log2(len);
return min(sp[i][k],sp[i+len-(1<<k)][k]);
}
int main()
{
int n,m,k,a,b;
cin>>n>>m;
k=log2(n)+1;
for(int i=0;i<n;i++)
cin>>sp[i][0];
for(int i=1;i<k;i++){
for(int j=0;j+(1<<(i-1))<n;j++){
sp[j][i]=min(sp[j][i-1],sp[j+(1<<(i-1))][i-1]);
}
}
for(int i=0;i<m;i++) cin>>a>>b,cout<<querty(a-1,b-1)<<"\n";
return 0;
}