https://www.luogu.org/problemnew/show/P3865
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int MAXN=100005,inf=1000000000;
int n,m,f[MAXN][30],k,l,r,p;
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&f[i][0]);
k=(int)(log(n)/log(2));
for(int j=1;j<=k;j++)
for (int i=1;i<=n-(1<<j)+1;i++)
f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
while(m--){
scanf("%d%d",&l,&r);
p=(int)(log(r-l+1)/log(2));
printf("%d\n",max(f[l][p],f[r-(1<<p)+1][p]));
}
return 0;
}