python 单调队列写法 卡空间 有无解决办法
查看原帖
python 单调队列写法 卡空间 有无解决办法
574739
Aoung楼主2022/3/10 09:47
arr = list(map(int,input().strip().split()))
# 求每一项前k个数的最小值
que = []
for i in range(n):
    if len(que) == 0:print(0)
    else:print(arr[que[0]])
    while len(que) > 0 and que[0] <= i - k: que.pop(0)
    while len(que) > 0 and arr[i] <= arr[que[-1]]: que.pop()
    que.append(i)

2022/3/10 09:47
加载中...