求助
#include<bits/stdc++.h>
using namespace std;
int Read();
int n,m;
int lg[100007],st[100007][51];
int main(){
n=Read();m=Read();
for(int i=1;i<=n;++i){
lg[i]=lg[i/2]+1;
st[i][0]=Read();
}
for(int i=1;i<=lg[n];++i)
for(int j=1;j+(1<<i)-1<=n;++j)
st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
while(m--){
int l=Read(),r=Read();
int len=lg[r-l+1];
cout<<max(st[l][len],st[r-(1<<len)+1][len])<<endl;
}
return 0;
}
int Read(){
char ch=getchar();int res=0,flag=1;
while(ch<'0'||ch>'9'){
if(ch=='-')flag=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
res=res*10+ch-'0';
ch=getchar();
}
return flag*res;
}