代码其实很好理解的qwq
估计是哪里细节没调好
#include<iostream>
#include<cmath>
#define f(i,j) max(i,j)
#define int long long
using namespace std;
int n,m,a[1000009];
int fen[5000];
int fs,x,y;
int tell(int l,int r){
int ans=a[l];
while(l%fs!=0){
ans=f(ans,a[l++]);
}
int num=(l/fs);
while(1){
if(l+fs>=r)break;
ans=f(ans,fen[num++]);
l+=fs;
}
while(l<=r){
ans=f(ans,a[l++]);
}
return ans;
}
main(){
cin>>n>>m;
fs=sqrt(n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
fen[(i-1)/fs]=f(fen[(i-1)/fs],a[i]);
}
for(int i=1;i<=m;i++){
scanf("%d%d",&x,&y);
printf("%d\n",tell(x,y));
}
}