0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 10:48:48 +00:00

P3865 【模板】ST表

R44425201
This commit is contained in:
Baoshuo Ren 2020-12-30 16:41:43 +08:00 committed by Baoshuo Ren
parent cda7fd96f7
commit e78eb6db61
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

24
problem/P3865/P3865.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <bits/stdc++.h>
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;
}