#11WA 求解
查看原帖
#11WA 求解
660009
shihan楼主2024/11/6 01:37
#include<bits/stdc++.h>
using namespace std;
long long a[1000005];
vector<long long>maxi;
vector<long long>mini;
int main()
{
	int n,k;
	deque<int>q;
	cin>>n>>k;
	for (int i=0;i<n;i++)
		cin>>a[i];
	for (int i=0;i<n;i++)
	{
		while (!q.empty() && a[q.back()]>=a[i])
			q.pop_back();
		q.push_back(i);
		if (i-q.front()>=k) q.pop_front();
		if (i>=k-1) cout<<a[q.front()]<<" ";
	}	
	cout<<endl;
	
	for (int i=0;i<n;i++)
	{
		while (!q.empty() && a[q.back()]<=a[i])
			q.pop_back();
		q.push_back(i);
		if (i-q.front()>=k) q.pop_front();
		if (i>=k-1) cout<<a[q.front()]<<" ";
	}	
	cout<<endl;
	return 0;
}
2024/11/6 01:37
加载中...