1
void rmq_init()
2

{
3
int i,j;
4
for(j=1;j<=n;j++) mx[j][0]=d[j];
5
int m=floor(log((double)n)/log(2.0));
6
for(i=1;i<=m;i++)
7
for(j=0;j+(1<<(i-1))<=n;j++)
8
mx[j][i]=max(mx[j][i-1],mx[j+(1<<(i-1))][i-1]);
9
}
10
11
int rmq(int l,int r)
12

{
13
int m=floor(log((double)(r-l+1))/log(2.0));
14
int a=max(mx[l][m],mx[r-(1<<m)+1][m]);
15
return a;
16
}
17
18

2



3

4

5

6

7

8

9

10

11

12



13

14

15

16

17

18

RMQ介紹:http://baike.baidu.com/view/1536346.htm
摘自某人文章:http://blog.sina.com.cn/s/blog_4d88e9860100cthl.html