0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 09:25:25 +00:00
OI-codes/Luogu/P3865/P3865.cpp

40 lines
719 B
C++
Raw Normal View History

#include <iostream>
#include <algorithm>
#include <cmath>
2020-12-30 08:41:43 +00:00
using std::cin;
using std::cout;
const char endl = '\n';
2020-12-30 08:41:43 +00:00
const int N = 1e5 + 5;
int n, m, k, t, f[N][25];
2020-12-30 08:41:43 +00:00
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
2020-12-30 08:41:43 +00:00
for (int i = 1; i <= n; i++) {
cin >> f[i][0];
2020-12-30 08:41:43 +00:00
}
t = std::__lg(n);
for (int i = 1; i <= t; i++) {
2020-12-30 08:41:43 +00:00
for (int j = 1; j <= n - (1 << i) + 1; j++) {
f[j][i] = std::max(f[j][i - 1], f[j + (1 << i - 1)][i - 1]);
2020-12-30 08:41:43 +00:00
}
}
for (int i = 1, l, r; i <= m; i++) {
cin >> l >> r;
k = std::__lg(r - l + 1);
cout << std::max(f[l][k], f[r - (1 << k) + 1][k]) << endl;
2020-12-30 08:41:43 +00:00
}
2020-12-30 08:41:43 +00:00
return 0;
}