zldyfn @ 2024-01-29 22:35:09
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
h,t=0,-1
for i in range(n):
while h<=t and a[i]<=a[b[t]]:
t-=1
t+=1
b[t]=i
if b[h]<i-k+1:
h+=1
if i>=k-1:
print(a[b[h]],end=' ')
print()
h,t=0,-1
for i in range(n):
while h<=t and a[i]>=a[b[t]]:
t-=1
t+=1
b[t]=i
if b[h]<i-k+1:
h+=1
if i>=k-1:
print(a[b[h]],end=' ')
by pigeonteam @ 2024-02-01 22:41:25
洛谷只保证 CCF
规定的信息竞赛语言在正确复杂度的情况下能过题,不保证其它语言的通过情况,望周知。