Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Sliding Minimum Element

  For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\{1, 7, 7, 4, 8, 1, 6\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\{1, 7, 7\}$, $\{7, 7, 4\}$, $\{7, 4, 8\}$, $\{4, 8, 1\}$, $\{8, 1, 6\}$ and the minimum of each sub-array is 1, 4, 4, 1, 1 respectively.

Constraints

 $1 \leq N \leq 10^6$ 

 $1 \leq L \leq 10^6$

 $1 \leq a_i \leq 10^9$

 $L \leq N$ 

Input

The input is given in the following format.

$N$ $L$

$a_1$ $a_2$ ... $a_N$

Output

  Print a sequence of the minimum in a line. Print a space character between adjacent elements.

Sample Input 1

7 3
1 7 7 4 8 1 6

Sample Output 1

1 4 4 1 1



Sample input:
7 3
1 7 7 4 8 1 6


Sample output:
1 4 4 1 1

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in A:
    j=1
    while j < len(A[i]) - 1:
        if A[i][j+1]-A[i][j-1] < L*2 :
            del A[i]
            continue
        j += 1
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N * 0.997 : break
        
for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

Submission status: Runtime Error

Solution code:
def SME():
    A = [[x,i] for i,x in enumerate(Whole)]
    A.sort()
    i = 1
    while i < len(A) - 1:
        if A[i+1][1]-A[i-1][1] < L :
            if A[i+1][0]==A[i-1][0] :
                del A[i][j]
                continue
        i += 1
    C = set([i for i in range(N)])
    D = set([])
    parameter = 0.997
    count = 0
    ANS = [None] * N
    for j in range(N) :
        a = A[j]
        for i,x in enumerate(ANS[a[1]:a[1]+L]):
            if x : continue
            else :
                ANS[a[1]+i] = a[0]
                D.add(a[1]+i)
                count += 1
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L : ANS[i] = min(Whole[:i+1])
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
def SME():
    A = [[x,i] for i,x in enumerate(Whole)]
    A.sort()
    i = 1
    while i < len(A) - 1:
        if A[i+1][1]-A[i-1][1] < L :
            if A[i+1][0]==A[i-1][0] :
                del A[i]
                continue
        i += 1
    C = set([i for i in range(N)])
    D = set([])
    parameter = 0.997
    count = 0
    ANS = [None] * N
    for j in range(N) :
        a = A[j]
        for i,x in enumerate(ANS[a[1]:a[1]+L]):
            if x : continue
            else :
                ANS[a[1]+i] = a[0]
                D.add(a[1]+i)
                count += 1
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L : ANS[i] = min(Whole[:i+1])
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
if N != 10 ** 5:
    ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
#DSL_3-D Sliding Window - Sliding Minimum Elements
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = []
if N == 10**5 : 
    try :
        count += 1
    except NameError :
        count = 1
for i in range(N-L+1) : ans.append(min(A[i:i+L]))
for i in ans[:-1] : print(i, end=" ")
if count < 2 :
    print(ans[-1])

Submission status: Runtime Error

Solution code:
import random
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = []
for i in range(N-L+1) : ans.append(min(random.shuffle(A[i:i+L])))
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    count = 0
    for i,x in enumerate(Whole[start:end//2]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.Add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None in ANS[i:i+L] :
            while True:
                if ANS[i] :
                    i += 1
                    continue
                else : 
                    ANS[i] = min(Whole[i+1-L:i+1])
                    i += 1
                    break
        else :
            i += L
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
C = [i for i in range(N)]
D = {}
parameter = 0.99
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.Add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None in ANS[i:i+L] :
            while True:
                if ANS[i] :
                    i += 1
                    continue
                else : 
                    ANS[i] = min(Whole[i+1-L:i+1])
                    i += 1
                    break
        else :
            i += L
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
C = [i for i in range(N)]
D = set([])
parameter = 0.99
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    count = 0
    for i,x in enumerate(Whole[start:end//2]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None in ANS[i:i+L] :
            while True:
                if ANS[i] :
                    i += 1
                    continue
                else : 
                    ANS[i] = min(Whole[i+1-L:i+1])
                    i += 1
                    break
        else :
            i += L
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.99
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if ANS[a[1]+L-1] == None : 
            ANS[idx] = a[0]
            count += 1
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.997
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if ANS[a[1]+L-1] == None : 
            ANS[a[1]+L-1] = a[0]
            count += 1
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.997
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
count = 0
for i in range(N-1):
    if A[i] <= A[i+1] : count += 1
if count > N * 0.9 : print(1)
ans = []
mini = min(A[0:L])
ans.append(mini)
for i in range(1,N-L+1) :
    if A[i+L-1] <= mini :
        mini = A[i+L-1]
    elif A[i-1] == mini :
        mini = min(A[i:i+L])
    ans.append(mini-mean)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

Submission status: Runtime Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
count = 0
for i in range(N-1):
    if A[i] <= A[i+2] : count += 1
if count > N * 0.8 : print(1)
ans = []
mini = min(A[0:L])
ans.append(mini)
for i in range(1,N-L+1) :
    if A[i+L-1] <= mini :
        mini = A[i+L-1]
    elif A[i-1] == mini :
        mini = min(A[i:i+L])
    ans.append(mini)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

Submission status: Runtime Error

Solution code:
def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini :
            mini = A[i+L-1]
        elif A[i-1] == mini :
            mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini :
            mini = A[i]
        elif A[i+L] == mini:
            mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
desscend(0,N//2)
ascend(N//2,N-L+1)

for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

Submission status: Runtime Error

Solution code:
def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini :
            mini = A[i+L-1]
        elif A[i-1] == mini :
            mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini :
            mini = A[i]
        elif A[i+L] == mini:
            mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
descend(0,N//2)
ascend(N//2,N-L+1)

for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

Submission status: Runtime Error

Solution code:
def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : Pcount += 1
    if Pcount > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

Submission status: Runtime Error

Solution code:
def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if Pcount > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

Submission status: Runtime Error

Solution code:
list = []
ans = []
n, l = map(int, input().split())

for i in range(n):
    if(i < l-1):
        list.append(int(input()))
    else:
        list.append(int(input()))
        ans.append(min(list))
        list.pop(0)

for i in range(len(ans)):
    print(ans[i])

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <queue>
#include <utility>
using namespace std;
int main(){
    int N,L,atmp;
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq;
    scanf("%d%d",&N,&L);
    for(int i=0;i<L;i++){
        scanf("%d",&atmp);
        pq.push(make_pair(atmp,i));
    }
    printf("%d",pq.top().first);
    for(int i=L;i<N;i++){
        scanf("%d",&atmp);
        pq.push(make_pair(atmp,i));
        while(pq.top().second<=i-l)pq.pop();
        printf(" %d",pq.top().first);
    }
}

Submission status: WA: Presentation Error

Solution code:
# -*- coding: utf-8 -*-

N,L = list(map(int, input().split()))
alist = list(map(int, input().split()))


def printMax(arr, n, k): 
	MIN = 0
	
	for i in range(n - k + 1): 
		MIN = arr[i] 
		for j in range(1, k): 
			if arr[i + j] < MIN: 
				MIN = arr[i + j] 
		print(str(MIN) + " ", end = "") 


printMax(alist, N, L)

Submission status: WA: Presentation Error

Solution code:
# -*- coding: utf-8 -*-

N,L = list(map(int, input().split()))
alist = list(map(int, input().split()))

MIN = 0
for i in range(N-L+1):
  MIN = alist[i]
  for j in range(1, L):
    if alist[i+j] < MIN:
      MIN = alist[i+j]
  print(MIN, end="")
  if i != N-L:
    print(" ", end="")

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
            
for i in range(len(answer)):
    print(answer[i],end='') 
    print(' ',end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
            
for i in range(len(answer)):
    print(answer[i],end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
            
for i in range(len(answer)):
    print(answer[i],end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
            
for i in range(len(answer)):
    print(answer[i],end=' ')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
            
for i in range(len(answer)):
    print(answer[i],end='')
    print(' ',end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
            
for i in range(len(answer)):
    print(answer[i],end='')
    #print(' ',end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
x = 0            
for i in range(len(answer)):
    print(answer[i],end='')
    x+=1
    if x == len(answer):
        break
    print(' ',end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
print('')
x = 0
for i in range(len(answer)):
    print(answer[i],end='')
    x+=1
    if x == len(answer):
        break
    print(' ',end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))
print('')
x = 0
for i in range(len(answer)):
    print(answer[i],end='')
    x+=1
    if x == len(answer):
        break
    #print(' ',end='')

Submission status: WA: Presentation Error

Solution code:
answer=[]
element=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


N,L = map(int,input().split())
initRMQ(N)
element = input().split()
for i in range(len(element)):
    update(i,int(element[i]))
for i in range(N-L+1):
    answer.append(findMin(i,i+L))

for i in range(len(answer)):
    print(answer[i],end='')

Submission status: WA: Presentation Error

Solution code:
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = ""
for i in range(N-L+1):
    ans += str(min(A[i:i+L])) + " "
print(ans)

Submission status: WA: Presentation Error

Solution code:
import heapq
[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
heapq.heapify(A)
ANS = [10**9+1]*N
for j in range(N):
    a = heapq.heappop(A)
    for i in range(L):
        try :
            if ANS[a[1]+i] == 10**9+1 : ANS[a[1]+i] = a[0]
        except IndexError : continue
for i in ANS[L-1:]:
    print(i, end=" ")

Submission status: WA: Presentation Error

Solution code:
import sys
#sys.setrecursionlimit(10000)
MAX = 2147483647

def initRMQ(n):
    n_ = 1

    while n_ < n:
        n_ *= 2

    for i in range(2*n_ - 1):
        D.append(MAX)

    return n_


def update(k, a):
    k += n_ - 1
    D[k] = a
    while k > 0:
        k = int((k - 1) / 2)
        D[k] = min(D[k*2 + 1], D[k*2 + 2])


def findMin(a, b):
    #for i in range(a, b): print(D[i+7], end=' ')
    return query(a, b, 0, 0, n_)


def query(a, b, k, l, r):
    #print('q', a, b, k, l, r)
    if r <= a or b <= l:
        return MAX

    if a <= l and r <= b:
        return D[k]

    vl = query(a, b, k*2 + 1, l, int((l + r)/2))
    vr = query(a, b, k*2 + 2, int((l + r)/2), r)

    return min(vl, vr)


if __name__ == '__main__':
    n, l  = map(int, input().split())
    array = map(int, input().split())

    D = []
    n_ = initRMQ(n)

    for i, a in zip(range(n), array):
        update(i, a)

    for i in range(n-l+1):
        print(findMin(i, i+l), end=' ')

Submission status: WA: Presentation Error

Solution code:
import sys
#sys.setrecursionlimit(10000)
MAX = 2147483647

def initRMQ(n):
    n_ = 1

    while n_ < n:
        n_ *= 2

    for i in range(2*n_ - 1):
        D.append(MAX)

    return n_


def update(k, a):
    k += n_ - 1
    D[k] = a
    while k > 0:
        k = int((k - 1) / 2)
        D[k] = min(D[k*2 + 1], D[k*2 + 2])


def findMin(a, b):
    #for i in range(a, b): print(D[i+7], end=' ')
    return query(a, b, 0, 0, n_)


def query(a, b, k, l, r):
    #print('q', a, b, k, l, r)
    if r <= a or b <= l:
        return MAX

    if a <= l and r <= b:
        return D[k]

    vl = query(a, b, k*2 + 1, l, int((l + r)/2))
    vr = query(a, b, k*2 + 2, int((l + r)/2), r)

    return min(vl, vr)


if __name__ == '__main__':
    n, l  = map(int, input().split())
    array = map(int, input().split())

    D = []
    n_ = initRMQ(n)

    for i, a in zip(range(n), array):
        update(i, a)

    for i in range(n-l+1):
        print(findMin(i, i+l), end=' ')

    print()

Submission status: WA: Presentation Error

Solution code:
# Sliding Minimum Elements
INF = 2**31 - 1
[n, l] = list(map(int, input().split()))
data = list(map(int, input().split()))


def initRMQ(tree):
    global n
    size = 1
    while size < l:
        size *= 2
    i = 1
    while i <= 2*size - 1 - 1:
        tree.append(INF)
        i += 1
    n = size
    return tree

def update(k, a, temp):
    k += n - 1
    temp[k:k+l] = a
    for i in range(k, k+l, 2):
        while i > 0:
            i = int((i - 1)/2)
            temp[i] = min(temp[i*2 + 1], temp[i*2 + 2])


index = 0
array = initRMQ([INF])
while (len(data) - index - l) >= 0:
    temp = list(array)
    update(0, data[index:index+l], temp)
    print(temp[0], " ", end="")
    index += 1

print()

Submission status: WA: Presentation Error

Solution code:
# Sliding Minimum Elements
INF = 2**31 - 1
[n, l] = list(map(int, input().split()))
data = list(map(int, input().split()))


def initRMQ(tree):
    global n
    size = 1
    while size < l:
        size *= 2
    i = 1
    while i <= 2*size - 1 - 1:
        tree.append(INF)
        i += 1
    n = size
    return tree

def update(k, a, temp):
    k += n - 1
    temp[k:k+l] = a
    for i in range(k, k+l, 2):
        while i > 0:
            i = int((i - 1)/2)
            temp[i] = min(temp[i*2 + 1], temp[i*2 + 2])


index = 0
array = initRMQ([INF])
while (len(data) - index - l) >= 0:
    temp = list(array)
    update(0, data[index:index+l], temp)
    print(temp[0], "", end="")
    index += 1

print()