Pagini recente » Cod sursa (job #407621) | Cod sursa (job #2754745) | Cod sursa (job #1767431) | Cod sursa (job #2090971) | Cod sursa (job #2920247)
#include<bits/stdc++.h>
using namespace std;
string numeFisier="rmq";
ifstream fin(numeFisier+".in"); ofstream fout(numeFisier+".out");
#define cin fin
#define cout fout
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
int n, m, a[100010][18];
int lg[100010];
int32_t main(){
INIT
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i][0];
}
for(int j=1; j<=17; j++){
for(int i=1; i<=(n-(1ll<<j)+1); i++){
a[i][j]=min(a[i][j-1], a[i+1ll<<(j-1)][j-1]);
}
}
for(int i=1, pow=0; i<=n; i++){
if((1ll<<(pow+1) )<=i){
pow++;
}
lg[i]=pow;
}
for(int i=1, l, r; i<=m; i++){
cin>>l>>r;
cout<<min( a[l][ lg[r-l+1] ], a[r-(1ll<<lg[r-l+1])+1 ][lg[r-l+1] ] )<<"\n";
}
return 0;
}