#include <bits/stdc++.h>
using namespace std;
#define int long long
char* p1, * p2, buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int read(){int x = 0, f = 1;char ch = nc();while (ch < 48 || ch>57){if (ch == '-')f = -1;ch = nc();}while (ch >= 48 && ch <= 57)x = x * 10 + ch - 48, ch = nc();return x * f;}
void write(int x){if (x < 0)putchar('-'), x = -x;if (x > 9)write(x / 10);putchar(x % 10 + '0');return;}
#define print(x) if(x==0)putchar('0');else write(x)
const int N = 1e7;
int n, a[N], f[N][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]);
}
signed main() {
n = read();
for (int i = 1; i <= n; i++)a[i] = read(), 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;
q = read();
while (q--) {
int l, r;
l = read(); r = read();
print(query(l, r));
putchar('\n');
}
return 0;
}
标签:p2,ch,int,p1,nc,问题,RMQ,define
From: https://www.cnblogs.com/breadcheese/p/18007626