From e78eb6db61d58945ba125c6fc8aef5621b4d4338 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 30 Dec 2020 16:41:43 +0800 Subject: [PATCH] =?UTF-8?q?P3865=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91ST?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R44425201 --- problem/P3865/P3865.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 problem/P3865/P3865.cpp diff --git a/problem/P3865/P3865.cpp b/problem/P3865/P3865.cpp new file mode 100644 index 00000000..ab074957 --- /dev/null +++ b/problem/P3865/P3865.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int n, m, l, r, k, t, f[100005][25]; + +int main() { + scanf("%d%d", &n, &m); + for (int i = 1; i <= n; i++) { + scanf("%d", &f[i][0]); + } + t = log(n) / log(2) + 1; + for (int i = 1; i < t; i++) { + for (int j = 1; j <= n - (1 << i) + 1; j++) { + f[j][i] = max(f[j][i - 1], f[j + (1 << i - 1)][i - 1]); + } + } + for (int i = 1; i <= m; i++) { + scanf("%d%d", &l, &r); + k = log(r - l + 1) / log(2); + printf("%d\n", max(f[l][k], f[r - (1 << k) + 1][k])); + } + return 0; +}