Start: Jun, 05, 2019 15:00:00
2019春ACM通识课考试(第二场)
End: Jun, 05, 2019 18:00:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 988ms
Memory: 32964kB
Author: 2018212212127
In contest: 1271

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int maxn=4e6+5;
const int inf=0x3f3f3f3f;
typedef long long ll;
int a[maxn],st[maxn];
void build(int o,int l,int r){
	if(l==r) st[o]=a[l];
	else{
		int mid=(l+r)>>1;
		build(o<<1,l,mid);
		build(o<<1|1,mid+1,r);
		st[o]=max(st[o<<1],st[o<<1|1]);
	}
}
int query(int o,int ql,int qr,int l,int r){
	if(ql<=l&&qr>=r){
		return st[o];
	}
	int ans=0;
	int mid=(l+r)>>1;
	if(ql<=mid) ans=max(ans,query(o<<1,ql,qr,l,mid));
	if(qr>=mid+1) ans=max(ans,query(o<<1|1,ql,qr,mid+1,r));
	return ans;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	build(1,1,n);
	for(int i=1;i+k-1<=n;i++) printf("%d\n",query(1,i,i+k-1,1,n));
}