90分求助 #1测试点错了
查看原帖
90分求助 #1测试点错了
269403
天宇1105楼主2020/10/13 13:57
#include <bits/stdc++.h>
using namespace std;
int n,k,q[1000001],e[1000001];
int head=0,tail=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	q[head]=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>e[i];
	}
	if(k==1)
	for (int i = 0; i < n; ++i)
	{
		cout<<e[i]<<" ";
	}
	else
	for (int i = 0; i < n; ++i)
	{
		if (i-q[head]>=k)
		{
			head++;
		}
		while((head<=tail)&&(e[q[tail]]>e[i])) tail--;
		tail++;
		q[tail]=i;
		if(i>=k-1)cout<<e[q[head]]<<" ";
	}
	cout<<endl;
	head=0,tail=0;
	if(k==1)
	for (int i = 0; i < n; ++i)
	{
		cout<<e[i]<<" ";
	}
	else
	for (int i = 0; i < n; ++i)
	{
		if (i-q[head]>=k)
		{
			head++;
		}
		while((head<=tail)&&(e[q[tail]]<e[i])) tail--;
		tail++;
		q[tail]=i;
		if(i>=k-1)cout<<e[q[head]]<<" ";
	}
	return 0;
}
2020/10/13 13:57
加载中...