标签:
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int n,f[1000011][30],a,b,q; int main() { freopen("climb.in","r",stdin); freopen("climb.out","w",stdout); scanf("%d",&n); for (int i=1;i<=n+1;i++) { scanf("%d",&a); f[i][0]=a; } for (int i=1;i<=20;i++) for (int j=1;j<=n;j++) if (j+(1<<i)-1<=n) f[j][i]=max(f[j][i-1],f[j+(1<<(i-1))][i-1]); else break; scanf("%d",&q); for (int i=1;i<=q;i++) { int temp; scanf("%d%d",&a,&b); a++;b++; temp=(int)(log(b-a+1.0)/log(2.0)); printf("%d\n",max(f[a][temp],f[b-(1<<temp)+1][temp])); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/sunshinezff/article/details/47087643