记录编号 |
581554 |
评测结果 |
AAAAAAAAA |
题目名称 |
[POJ 2823]滑动窗口 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
2.810 s |
提交时间 |
2023-08-05 12:44:21 |
内存使用 |
194.56 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 1100010;
int n,m;
int a[N];
int mi[N][22],ma[N][22];
int main(){
freopen("window.in","r",stdin);
freopen("window.out","w",stdout);
scanf("%d%d",&n,&m);
memset(mi,0x3f,sizeof(mi));
memset(ma,-0x3f,sizeof(ma));
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
mi[i][0] = ma[i][0] = a[i];
}
int t = int(log(n)/log(2));
for(int j = 1;j <= t;j++){
for(int i = 1;i <= n;i++){
int l = pow(2,j-1);
mi[i][j] = min(mi[i][j-1],mi[i+l][j-1]);
ma[i][j] = max(ma[i][j-1],ma[i+l][j-1]);
}
}
t = int(log(m)/log(2));
int u = pow(2,t);
for(int l = 1;l+m-1 <= n;l++){
int r = l+m-1;
printf("%d ",min(mi[l][t],mi[r-u+1][t]));
}
printf("\n");
for(int l = 1;l+m-1 <= n;l++){
int r = l+m-1;
printf("%d ",max(ma[l][t],ma[r-u+1][t]));
}
return 0;
}