记录编号 352637 评测结果 AAAAAAAAAA
题目名称 延绵的山峰 最终得分 100
用户昵称 Gravatar_Itachi 是否通过 通过
代码语言 C++ 运行时间 1.748 s
提交时间 2016-11-17 14:55:06 内存使用 88.03 MiB
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1000005;
int n,m,Log[maxn],L2[maxn],f[maxn][21],Len=0;
void Rabit_in(){
	scanf("%d",&n);int i,v=1;
	scanf("%d",&i);
	for(i=1;i<=n;i++){
		scanf("%d",&f[i][0]);
		Log[i]=Len;
		if(i==v)v<<=1,Len++;
	}
	//for(i=1;i<=n;i++)printf("%d ",Log[i]);
}
int Rabit_max(int a,int b){return a>b?a:b;}
void Rabit_run(){
	int v,i,t,V;
	for(v=1;v<=Len;v++)
	for(V=1<<(v-1),t=n-(V<<1)+1,i=1;i<=t;i++)
		f[i][v]=Rabit_max(f[i][v-1],f[i+V][v-1]);	
}
int Rabit_get(int l,int r){
	int len=r-l+1;len=Log[len]-1;
	return Rabit_max(f[l][len],f[r-(1<<len)+1][len]);
}
void Rabit_ans(){
	int l,r;scanf("%d",&m);
	while(m--){
		scanf("%d%d",&l,&r);
		if(l==r){printf("%d\n",f[l][0]);continue;}
		if(!l)l++;
		printf("%d\n",Rabit_get(l,r));
	}	
}
void Rabit_main(){
	Rabit_in();
	Rabit_run();
	Rabit_ans();
}
int main(){
#define _Rabit _RABIT
#ifdef _Rabit
	freopen("climb.in","r",stdin);
	freopen("climb.out","w",stdout);
#endif
	Rabit_main();
#ifndef _Rabit
	getchar(),getchar();
#endif
	fclose(stdin);fclose(stdout);
	return 0;
}