Heart_Of_Iron_4 @ 2022-01-28 12:42:46
记录
测试点1输出一样,却WA
#include<bits/stdc++.h>
using namespace std;
int a[100100],n,m;
int h[200100],hd,lt=0;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
h[0]=INT_MIN;
for(int i=1;i<m;++i)
{
h[++lt]=i;
while(lt>hd+1&&a[h[lt]]<a[h[lt-1]])
{
h[lt-1]=h[lt];
lt--;
}
}
puts("");
for(int i=m;i<=n;++i)
{
if(h[hd+1]<i-m+1)
{
hd++;
h[hd-1]=INT_MIN;
}
h[++lt]=i;
while(lt>hd+1&&a[h[lt]]<a[h[lt-1]])
{
h[lt-1]=h[lt];
lt--;
}
printf("%d ",a[h[hd+1]]);
}
puts("");
h[0]=INT_MAX;
hd=0,lt=0;
for(int i=1;i<m;++i)
{
h[++lt]=i;
while(lt>hd+1&&a[h[lt]]>a[h[lt-1]])
{
h[lt-1]=h[lt];
lt--;
}
}
for(int i=m;i<=n;++i)
{
if(h[hd+1]<i-m+1)
{
hd++;
h[hd-1]=INT_MIN;
}
h[++lt]=i;
while(lt>hd+1&&a[h[lt]]>a[h[lt-1]])
{
h[lt-1]=h[lt];
lt--;
}
printf("%d ",a[h[hd+1]]);
}
return 0;
}
by newbie_QwQ @ 2022-01-28 13:19:01
您这头像······