蒟蒻求助
  • 板块学术版
  • 楼主liuchenyi0203
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/1/17 19:40
  • 上次更新2023/10/28 12:07:16
查看原帖
蒟蒻求助
245459
liuchenyi0203楼主2022/1/17 19:40

rt

时间不够

TLE了

其他全AC,56分代码 有没有dalao神犇来帮我改改

// LG-P3865.cpp
#include <cstdio>
#include <iostream>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
typedef long long ll;
const int maxn=2e5+5;
int n,m;
int a[maxn];
int f[maxn][21],log_2[maxn];
int main(){
	n=read();
	m=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		f[i][0]=a[i];
	}
	for(int i=1;i<=20;i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
			f[j][i]=max(f[j][i-1],f[j+(1<<(i-1))][i-1]);
	for(int i=2;i<=n;i++)
		log_2[i]=log_2[i/2]+1;
	while(m--){
		int l,r,s,ans;
		l=read();
		r=read();
		s=log_2[r-l+1];
		ans=max(f[l][s],f[r-(1<<s)+1][s]);
		cout<<ans<<endl;
	}
	return 0;
}
2022/1/17 19:40
加载中...