【luogu P3865 ST表】 模板

跟忠诚是一样滴,不过是把min改成max就AC了。模板题。

 1 #include <cstdio> 
 2 #include <algorithm>
 3 using namespace std;
 4 const int maxn = 1000000;
 5 int st[maxn][21], a[maxn], ans[maxn];
 6 int i, j, n, m, left, right;
 7 int main()
 8 {
 9     scanf("%d%d", &n, &m);
10     for(i = 1; i <= n; i++)
11     {
12         scanf("%d", &a[i]);
13         st[i][0] = a[i];
14     }
15     
16     for(j = 1; (1<<j) <= n; j++)
17         for(i = 1; i <= n - (1<<j) + 1; i++)
18         st[i][j] = max(st[i][j-1] , st[i + (1<< (j-1) )][j-1]);
19     
20     for(i = 1; i <= m; i++)
21     {
22         scanf("%d%d", &left, &right);
23         j = 0;
24         while((1<<(j+1)) <= (right-left+1)) j++;
25         ans[i] = max(st[left][j],st[right-(1<<j)+1][j]);
26     }
27     
28     for(i = 1; i <= m; i++)
29     printf("%d\n",ans[i]);
30     return 0;
31 }

 

posted @ 2018-02-26 09:07  Misaka_Azusa  阅读(179)  评论(0编辑  收藏  举报
Live2D