$O(nlogn)$构造$O(1)$查询真是太强辣
然而不支持修改= =
ShØut!
1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<cmath>
5 using namespace std;
6 int n,q,l,r,num[100001],st[100001][20];
7 int main(){
8 scanf("%d%d",&n,&q);
9 for(int i=1;i<=n;i++){
10 scanf("%d",&num[i]);
11 st[i][0]=num[i];
12 }
13 for(int j=1;j<=(int)log2(n);j++){
14 for(int i=1;i<=n;i++){
15 if(i+(1<<j)-1<=n){
16 st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
17 }
18 }
19 }
20 for(int i=1;i<=q;i++){
21 scanf("%d%d",&l,&r);
22 int k=(int)log2(r-l+1);
23 printf("%d
",max(st[l][k],st[r-(1<<k)+1][k]));
24 }
25 return 0;
26 }