快速幂
区间最小值(用倍增思想去求)
#include<bits/stdc++.h>
using namespace std;
#define maxn 110000
#define ll long long
int n, a[maxn], f[maxn][40];
int query (int l, int r)
{
int k = (int)(log((r - l + 1) * 1.0) / log(2.0));
return min(f[l][k], f[r - (1 << k) + 1][k]);
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++ i )
scanf("%d", &a[i]), f[i][0] = a[i];
for (int j = 1; j <= (int)(log(n * 1.0) / log(2.0)); ++ j )
for (int i = 1; i + (1 << j) - 1 <= n; ++ i )
f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
int q;
scanf("%d", q);
while (q -- )
{
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", query(l, r));
}
return 0;
}