Pagini recente » Cod sursa (job #3193199) | Cod sursa (job #3218907)
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) ;
#define ll long long
ifstream fin("rmq.in") ;
ofstream fout("rmq.out") ;
const int NMAX=1e5+5 ;
int n,dp[17][NMAX],q ;
inline int f(int val)
{
return 1<<val ;
}
int main()
{
fin>>n>>q ;
for(int i=1; i<=n; ++i) fin>>dp[0][i] ;
for(int i=1; i<17; ++i)
for(int j=1; j<=n-(1<<i)+1; ++j) dp[i][j]=min(dp[i-1][j],dp[i-1][j+f(i-1)]) ;
while(q--)
{
int x,y,l ;
fin>>x>>y ;
l=log2(y-x+1) ;
fout<<min(dp[l][x],dp[l][y-(1<<(l-1))])<<'\n' ;
}
return 0;
}