天天看點

poj 2823 Sliding Window

time limit: 12000ms

memory limit: 65536k

total submissions: 36147

accepted: 10700

case time limit: 5000ms

description

an array of size n ≤ 106 is given to you. there is a sliding window of size k which is moving from the very left of the array to the very right. you can only see the k numbers in the window. each time the sliding window

moves rightwards by one position. following is an example: 

the array is [1 3 -1 -3 5 3 6 7], and k is 3.

window position

minimum value

maximum value

[1  3  -1] -3  5  3  6  7 

-1

3

 1 [3  -1  -3] 5  3  6  7 

-3

 1  3 [-1  -3  5] 3  6  7 

5

 1  3  -1 [-3  5  3] 6  7 

 1  3  -1  -3 [5  3  6] 7 

6

 1  3  -1  -3  5 [3  6  7]

7

your task is to determine the maximum and minimum values in the sliding window at each position. 

input

the input consists of two lines. the first line contains two integers n and k which are the lengths of the array and the sliding window. there are n integers in the second line. 

output

there are two lines in the output. the first line gives the minimum values in the window at each position, from left to right, respectively. the second line gives the maximum values. 

sample input

sample output

線段樹、區間求最值