嗯...
题目链接:https://www.luogu.org/problemnew/show/P3865
AC代码:
1 #include2 #include 3 #include 4 5 using namespace std; 6 7 int m, n, a[200005], st[200005][35]; 8 9 int main(){10 scanf("%d%d", &n, &m);11 for(int i = 1; i <= n; i++){12 scanf("%d", &a[i]);13 st[i][0] = a[i];14 }15 for(int j = 1; j <= log2(n); j++){16 for(int i = 1; i + (1 << j) - 1 <= n; i++){17 st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);18 }19 }20 for(int i = 1; i <= m; i++){21 int l, r;22 scanf("%d%d", &l, &r);23 int k = log2(r - l + 1);24 printf("%d\n", max(st[l][k], st[r - (1 << k) + 1][k]));25 }26 return 0;27 }