记录编号 |
586141 |
评测结果 |
AAAAAAAAA |
题目名称 |
[POJ 2823]滑动窗口 |
最终得分 |
100 |
用户昵称 |
jacken |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.642 s |
提交时间 |
2024-01-06 18:46:29 |
内存使用 |
66.77 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6;
int a[N];
int f[N][20];
int n,k;
int main()
{
freopen("window.in","r",stdin);
freopen("window.out","w",stdout);
scanf("%d %d",&n,&k);
for(int i = 1;i<=n;i++)
{
scanf("%d",&a[i]);
f[i][0] = a[i];
}
for(int i = 1;i<=log2(n);i++)
{
for(int j = 1;j<=n-(1<<i)+1;j++)
{
f[j][i] = min(f[j][i-1],f[j+(1<<(i-1))][i-1]);
}
}
for(int i = 1;i+k-1<=n;i++)
{
int x = i,y = i+k-1;
int k = log2(y-x+1);
printf("%d ",min(f[x][k],f[y-(1<<k)+1][k]));
}
printf("\n");
for(int i = 1;i<=n;i++)
{
f[i][0] = a[i];
}
for(int i = 1;i<=log2(n);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+k-1<=n;i++)
{
int x = i,y = i+k-1;
int k = log2(y-x+1);
printf("%d ",max(f[x][k],f[y-(1<<k)+1][k]));
}
return 0;
}