比赛 至少完成十道练习 评测结果 AAAAAAAAA
题目名称 滑动窗口 最终得分 100
用户昵称 FFF团 运行时间 2.885 s
代码语言 C++ 内存使用 236.82 MiB
提交时间 2017-05-21 21:10:14
显示代码纯文本
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1000001;
const int INF=0x7fffffff;
int maxx[maxn][30],minn[maxn][30];
int Min,Max,n,k;
int ans1[maxn],ans2[maxn];
void query(int l,int r){
	int k=0;
	while((1<<(k+1))<=r-l+1)k++;
	ans1[l]=min(minn[l][k],minn[r-(1<<k)+1][k]);
	ans2[l]=max(maxx[l][k],maxx[r-(1<<k)+1][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",&minn[i][0]);
	memcpy(maxx,minn,sizeof(minn));
	for(int j=1;(1<<j)<=n;j++)
	for(int i=1;i+(1<<j)-1<=n;i++){
		minn[i][j]=min(minn[i+(1<<(j-1))][j-1],minn[i][j-1]);
		maxx[i][j]=max(maxx[i+(1<<(j-1))][j-1],maxx[i][j-1]);
	}
    for(int i=1;i<=n-k+1;i++)query(i,i+k-1);
	for(int i=1;i<=n-k+1;i++)printf("%d ",ans1[i]);
	printf("\n");
	for(int i=1;i<=n-k+1;i++)printf("%d ",ans2[i]);
	return 0;
}