到底哪个是对的啊救命救命
查看原帖
到底哪个是对的啊救命救命
750911
Little_Joker楼主2023/11/17 11:20

明天就AFO了,复习板子发现

#include<cmath>
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
inline int read()
{
	int x=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int maxn=1e6+10;
int n,m;
ll st[maxn][26];
void ST()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)
	{
		st[i][0]=read();
	}
	for(int k=1;k<=25;k++)
		for(int i=1;i+(1<<k)-1<=n;i++)	//here
			st[i][k]=max(st[i][k-1],st[i+(1<<(k-1))][k-1]);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		x=read();y=read();
		int p=log2(y-x+1);
		printf("%lld\n",max(st[x][p],st[y-(1<<p)+1][p]));
		
	}
}
int main()
{
	ST();
	return 0;
}
#include<cmath>
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
inline int read()
{
	int x=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int maxn=1e6+10;
int n,m;
ll st[maxn][26];
void ST()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)
	{
		st[i][0]=read();
	}
	for(int k=1;k<=25;k++)
		for(int i=1;i+(1<<(k-1))<=n;i++)	//here
			st[i][k]=max(st[i][k-1],st[i+(1<<(k-1))][k-1]);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		x=read();y=read();
		int p=log2(y-x+1);
		printf("%lld\n",max(st[x][p],st[y-(1<<p)+1][p]));
		
	}
}
int main()
{
	ST();
	return 0;
}

帮忙看看吧[大哭]

2023/11/17 11:20
加载中...