有没有大佬帮我看看为什么错
查看原帖
有没有大佬帮我看看为什么错
909367
MA_tian楼主2023/12/29 23:58

不知道为什么错,连输入都不行,调了一晚上了,rt

#include<bits/stdc++.h>
using namespace std;
int f[200005][20],a[200005];
int main(){
	ios::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int j=0;j<=18;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			if(!j){
				f[i][j]=a[i];
			}else{
				f[i][j]=max(f[i][j-1],f[i+(1<<j-1)][j-1]);
			}
		}
	}
	while(m--){
		int c,d;
		cin>>c>>d;
		int len=c-d+1,k=log(len)/log(2);
		cout<<max(f[c][k],f[d-(1<<k)+1][k])<<endl;
	}
	return 0;
}
2023/12/29 23:58
加载中...