49,求调
查看原帖
49,求调
1185777
_WHMG_楼主2024/1/16 21:04
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,q,A[N],st[N][20];
inline void Pre(){
	for(int i=1;i<=n;i++) st[i][0]=A[i];
	for(int j=1;(1<<j)<=n;j++)
		for(int i=1;i+(1<<j)-1<=n;i++)
			st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
inline int ask(int l,int r){
	int j=__lg(r-l+1);
	return max(st[l][j],st[r-(1<<j)+1][j]);
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++)
		cin>>A[i];
	Pre();
	for(int i=1;i<=n;i++){
		int r,l;
		cin>>l>>r;
		cout<<ask(l,r)<<'\n';
	}
	return 0;
}
2024/1/16 21:04
加载中...