You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 100010;
|
|
|
|
|
int a[N];
|
|
|
|
|
int n, q;
|
|
|
|
|
|
|
|
|
|
/*ST跳表:快速查询区间内的极大极小值*/
|
|
|
|
|
int st1[N][40], st2[N][40];
|
|
|
|
|
void build() {
|
|
|
|
|
for (int i = 1; i <= n; i++) st1[i][0] = a[i], st2[i][0] = a[i];
|
|
|
|
|
for (int j = 1; (1 << j) <= n; j++)
|
|
|
|
|
for (int i = 1; (i + (1 << j) - 1) <= n; i++) {
|
|
|
|
|
st1[i][j] = max(st1[i][j - 1], st1[i + (1 << (j - 1))][j - 1]);
|
|
|
|
|
st2[i][j] = min(st2[i][j - 1], st2[i + (1 << (j - 1))][j - 1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int queryMax(int x, int y) {
|
|
|
|
|
int t = log2(y - x + 1);
|
|
|
|
|
return max(st1[x][t], st1[y - (1 << t) + 1][t]);
|
|
|
|
|
}
|
|
|
|
|
int queryMin(int x, int y) {
|
|
|
|
|
int t = log2(y - x + 1);
|
|
|
|
|
return min(st2[x][t], st2[y - (1 << t) + 1][t]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
5
|
|
|
|
|
50 60 45 39 78
|
|
|
|
|
2 5
|
|
|
|
|
|
|
|
|
|
答案应该是45
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
signed main() {
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
|
|
|
|
|
build();
|
|
|
|
|
int x, y;
|
|
|
|
|
scanf("%d %d", &x, &y);
|
|
|
|
|
cout << queryMax(x, y) << endl;
|
|
|
|
|
cout << queryMin(x, y) << endl;
|
|
|
|
|
}
|