11、12WA
查看原帖
11、12WA
1061050
jiangyunuo楼主2025/7/30 18:43
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b[100005][25],l,r,c,d,tot;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		b[i][0]=a;
	}
	for(int j=1;j<=20;j++){
		c=1<<j;
		if(c>n)break;
		for(int i=1;i<=n;i++){
			if(i+c-1>n)break;
			b[i][j]=max(b[i][j-1],b[i+c/2][j-1]);
		}
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&l,&r);
		d=0;
		tot=20;
		while(l<r){
			c=1<<tot;
			if(l+c-1<=r){
				d=max(b[l][tot],d);
				l+=c-1;
			}
			else tot--;
		}
		printf("%d\n",d);
	}
	return 0; 
}
2025/7/30 18:43
加载中...