Wangtsjo @ 2022-03-31 20:14:17
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
deque<long long>q;
long long a[100009],n,k;
int main()
{
cin>>n;
scanf("%lld",&k);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
for(int i=1;i<=n;i++)
{
while(!q.empty()&&q.front()<i-k+1)
q.pop_front();
while(!q.empty()&&a[q.back()]>=a[i])
{
q.pop_back();
}
q.push_back(i);
if(i>k-1) printf("%lld ",a[q.front()]);
}
printf("\n");//求最小值
q.clear();//清空
for(int i=1;i<=n;i++)
{
while(!q.empty()&&q.front()<i-k+1)
q.pop_front();
while(!q.empty()&&a[q.back()]<=a[i])
{
q.pop_back();
}
q.push_back(i);
if(i>k-1) printf("%lld ",a[q.front()]);
}
return 0;
}//求最大值
谢谢各位大佬!!
by Day0 @ 2022-03-31 21:53:26
数组开小了
by Wangtsjo @ 2022-04-01 13:07:56
@hhdxgd 我的问题()