RMQ的大裸题。没什么意思。开始数组开小了,RE了一次。下面放代码。
#include <bits/stdc++.h>
using namespace std; vector<int> A;
int dp[][]; void RMQ_init () {
int n = A.size();
for (int i = ; i < n; ++ i) {
dp[i][] = A[i];
}
for (int j = ; ( << j) <= n; ++ j) {
for (int i = ; i + ( << j) - < n; ++ i) {
dp[i][j] = min(dp[i][j - ], dp[i + ( << (j - ))][j - ]);
}
}
} int RMQ (int L, int R) {
int k = ;
while (( << (k + )) <= R - L + ) ++ k;
return min(dp[L][k], dp[R - ( << k) + ][k]);
} int main () {
int n;
while (~scanf ("%d", &n)) {
int x, op_n;
for (int i = ; i < n; ++ i) {
scanf ("%d", &x);
A.push_back(x);
}
/*
for (int i = 0; i < A.size() - 1; ++ i) {
cout << A[i] << endl;
}
*/
RMQ_init ();
int a, b;
scanf ("%d", &op_n);
for (int i = ; i < op_n; ++ i) {
scanf ("%d%d", &a, &b);
printf ("%d\n", RMQ(a - , b - ));
}
}
return ;
}