bro以为这题是ST表💀💀💀
2024-07-27 09:14:40
发布于:湖南
10阅读
0回复
0点赞
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int a[1000005], f1[30][1000005], f2[30][1000005];
int read(){
char c = getchar();
int x = 0, f = 1;
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)){
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * f;
}
void _write(int n){
if(n == 0) return;
_write(n / 10);
putchar(n % 10 + '0');
}
void write(int n, bool end = 0){
if(n < 0) putchar('-'), _write(-n);
else if(n == 0) putchar('0');
else _write(n);
if(end) putchar(' ');
}
int main(){
int n = read(), m = read();
int len = log2(m);
for(int i = 1; i <= n; i++){
f1[0][i] = f2[0][i] = a[i] = read();
}
for(int i = 1; (1 << i) <= n; i++){
for(int j = 1; j <= n - (1 << i) + 1; j++){
f1[i][j] = max(f1[i - 1][j], f1[i - 1][j + (1 << i >> 1)]);
f2[i][j] = min(f2[i - 1][j], f2[i - 1][j + (1 << i >> 1)]);
}
}
for(int i = 1; i <= n - m + 1; i++){
write(min(f2[len][i], f2[len][i + m - (1 << len)]), 1);
}putchar('\n');
for(int i = 1; i <= n - m + 1; i++){
write(max(f1[len][i], f1[len][i + m - (1 << len)]), 1);
}
return 0;
}
这里空空如也
有帮助,赞一个