代码求调24pts WA
查看原帖
代码求调24pts WA
571445
Star_Whale楼主2023/8/4 22:46
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
int n,m,x[N],st[N][200];
void ST()
{
	int p=log(n)/log(2);
	for(int k=1;k<=p;k++)
		for(int i=1;i<=n-(1<<k)+1;i++)
			st[k][i]=max(st[k-1][i],st[k-1][i+(1<<(k-1))]);
}
int query(int l,int r)
{
    int p=log(r-l+1)/log(2);
    return max(st[p][l],st[p][r-(1<<p)+1]);
}			
		
signed main() 
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%lld",&st[0][i]);
	ST();
	while(m--)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		int ans=query(x,y);
		printf("%lld\n",ans);
	}	 
    return 0;
 }
2023/8/4 22:46
加载中...