你说的对,但是…… (1/3)
  • 板块灌水区
  • 楼主_xEr_
  • 当前回复43
  • 已保存回复43
  • 发布时间2023/8/9 11:28
  • 上次更新2023/11/3 05:01:15
查看原帖
你说的对,但是…… (1/3)
672815
_xEr_楼主2023/8/9 11:28

但是分块做ST表真的很难调

#include<iostream>
#include<cmath> 
#define f(i,j) max(i,j)
#define int long long
using namespace std;
int n,m,a[1000009];
int fen[5000];
int fs,x,y;
int tell(int l,int r){
	int ans=a[l];
	while(l%fs!=0){
		ans=f(ans,a[l++]);
	}
	int num=(l/fs);
	while(1){
		if(l+fs>=r)break;
		ans=f(ans,fen[num++]);
		l+=fs;	
	}
	while(l<=r){
		ans=f(ans,a[l++]);
	}
	return ans;
	
}
main(){
	cin>>n>>m;
	fs=sqrt(n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		fen[(i-1)/fs]=f(fen[(i-1)/fs],a[i]);
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		printf("%d\n",tell(x,y));
	}
}
2023/8/9 11:28
加载中...