标签:div name names fine can using span space max
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define maxn 1005 using namespace std; int a[maxn],mx[maxn][20]; int n,q,T,l,r; void ST(){ for(int i=1;i<=n;i++) mx[i][0]=a[i]; for(int j=1;(1<<j)<=n;j++) for(int i=1;i+(1<<j)-1<=n;i++) mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]); } int query(int L,int R){ int k=0; while((1<<(k+1))<=R-L+1) k++; return max(mx[L][k],mx[R-(1<<k)+1][k]); } int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); ST(); scanf("%d",&q); while(q--){scanf("%d%d",&l,&r);printf("%d\n",query(l,r));} } }
标签:div name names fine can using span space max
原文地址:https://www.cnblogs.com/zsben991126/p/10021156.html