Pagini recente » Cod sursa (job #1978701) | Cod sursa (job #2952223) | Cod sursa (job #920495) | Cod sursa (job #61159) | Cod sursa (job #2644986)
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();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
ifstream fin("rmq.in"); ofstream fout("rmq.out");
//#define cin fin
//#define cout fout
#define int ll
int t, n, m, k, a[300010], q, l;
int rmq[100010][20], lg[100010];
void build_RMQ(){
for(int i=1; i<=20; i++ ){
for(int j=1;(j+(1LL<<i)-1)<=n; j++){
rmq[j][i]=min(rmq[j][i-1], rmq[j+(((int) 1)<<(i-1) ) ][i-1]);
}
}
int l=0;
for(int i=1; i<=n; i++){
if( (1LL<<(l+1))<=(i) ){l++;}
lg[i]=l;
cout<<i<<" "<<l<<" || "<<flush;
}
}
int min_query(int l, int r){
int rng=lg[r-l+1];
return min( rmq[l][rng], rmq[r-(((int)1)<<rng)+1 ][rng] );
}
int32_t main(){
INIT
cin>>n>>q;
for(int i=1; i<=n; i++){
cin>>a[i]; rmq[i][0]=a[i];
}
build_RMQ();
for(;q;q--){
int x, y;
cin>>x>>y;
cout<<min_query(x, y)<<"\n";
}
return 0;
}