本文最后更新于573 天前,其中的信息可能已经过时,如有错误请发送邮件到1739584917@qq.com
#include <iostream>
using namespace std;
const int MAX = 2000010;
int f[MAX][50], logn[MAX]= {-1};
int main() {
int n,m;
cin>>n>>m;
for (int i = 1; i <= n; i++)
{
cin>>f[i][0];
logn[i] = logn[i/2] + 1; //预处理log函数
}
//预处理最大值
for (int j = 1; j <= logn[n]; j++)
for (int i = 1; i + (1 << j) - 1 <= n; i++)
f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
while(m--)
{
int x, y;
cin>>x>>y;
int s = logn[y - x + 1];
printf("%d\n", max(f[x][s], f[y - (1 << s) + 1][s]));
}
return 0;
}