Pagini recente » Cod sursa (job #663710) | Cod sursa (job #1819058) | Cod sursa (job #3305475) | Cod sursa (job #3307054) | Cod sursa (job #3329737)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 100000;
const int LOG = 20;
int st[MAXN+5][LOG];
int lg[MAXN+5];
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int N,M; cin>>N>>M;
for(int i=0;i<N;i++){
cin>>st[i][0];
}
lg[1]=0;
for(int i=2;i<=N;i++) lg[i]=lg[i/2]+1;
for(int j=1;j<LOG;j++){
for(int i=0;i+(1<<j)<=N;i++){
st[i][j]=min(st[i][j-1], st[i+(1<<(j-1))][j-1]);
}
}
while(M--){
int L,R; cin>>L>>R;
L--; R--;
int len=R-L+1;
int k=lg[len];
int ans=min(st[L][k], st[R-(1<<k)+1][k]);
cout<<ans<<"\n";
}
return 0;
}