https://www.luogu.org/problemnew/show/1816
st表模板
#include<cstdio> #include<algorithm> using namespace std; typedef long long LL; LL m,n; LL a[100100],d[100100][20]; int main() { LL i,j,l,r,k; scanf("%lld%lld",&m,&n); for(i=1;i<=m;i++) scanf("%lld",&a[i]); for(i=1;i<=m;i++) d[i][0]=a[i]; for(j=1;(1<<j)<=m;j++)//注意j和i的顺序 for(i=1;i+(1<<j)-1<=m;i++) d[i][j]=min(d[i][j-1],d[i+(1<<(j-1))][j-1]); for(i=1;i<=n;i++) { scanf("%lld%lld",&l,&r); k=0; while((1<<(k+1))<=r-l+1) k++; printf("%lld ",min(d[l][k],d[r-(1<<k)+1][k])); } return 0; }