#include<bits/stdc++.h> const int N=1e6+5; const int Logn=20; int f[N][Logn],a[N],lg[N],n,m; int main(){ cin>>n>>m; rep(i,1,n) cin>>a[i]; lg[0]=-1; rep(i,1,n) fa[i][0]=a[i],lg[i]=lg[i>>1]+1; rep(j,1,Logn) for(int i=1;i+(1<<j)-1<=n;i++) f[i][j]=max(f[i][j-1],f[i+(1<<j-1)][j-1]); while(m--){ int x,y;cin>>x>>y; int k=lg[y-x+1]; printf("%d\n",max(f[x][k],f[y-(1<<k)+1][k]));} return 0; }
原文地址:https://www.cnblogs.com/asdic/p/9609017.html
时间: 2024-10-05 23:57:59