24pts RE 求调
查看原帖
24pts RE 求调
800322
Zouzhuoxuan楼主2023/8/25 11:53
#include<bits/stdc++.h>
#define int long long
#define N 114514
using namespace std;
inline int read()
{
	int n=0,f=1;
	char c=getchar();
	while(c<'0' || c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9') n=(n<<3)+(n<<1)+(c^48),c=getchar();
	return n*f;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10^48);
	return;
}
int st[505][505];
signed main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,m,i,j;
	n=read(),m=read();
	for(i=1;i<=n;i++) st[i][0]=read();
	for(i=1;i<=21;i++) for(j=1;j+(1<<i)-1<=n;j++) st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
	while(m--)
	{
		int l=read(),r=read(),len;
		len=log2(r-l+1);
		write(max(st[l][len],st[r-(1<<len)+1][len])),puts("");
	}
	return 0;
}
2023/8/25 11:53
加载中...