明天就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;
}
帮忙看看吧[大哭]