10pts,蒟蒻救助
查看原帖
10pts,蒟蒻救助
591719
wangxinyu5483楼主2024/10/8 19:40

求助!!!10pts

#include<bits/stdc++.h>
using namespace std;
long long a[10000000],n,k,temp;
deque<long long>q;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	temp=0;
	for(long long i=1;i<=n;i++)
	{
		while(!q.empty()&&q.back()>=a[i])
		{
			q.pop_back();
		}
		q.push_back(a[i]);
		if(i-temp>=k&&a[temp]==q.front())
		{
			temp++;
			q.pop_front();
		}
		if(i-temp>=k&&a[temp]!=q.front())
		{
			temp++;
		}
		if(i>=k-1)
		{
			cout<<q.front()<<' ';
		}
	}
	printf("\n");
	q.clear();
	temp=0;
	for(long long i=1;i<=n;i++)
	{
		while(!q.empty()&&q.back()<=a[i])
		{
			q.pop_back();
		}
		q.push_back(a[i]);
		if(i-temp>=k&&a[temp]==q.front())
		{
			temp++;
			q.pop_front();
		}
		if(i-temp>=k&&a[temp]!=q.front())
		{
			temp++;
		}
		if(i>=k-1)
		{
			cout<<q.front()<<' ';
		}
	}
	return 0;
}
2024/10/8 19:40
加载中...