A monotonic queue is a deque (double-ended queue) that maintains elements in sorted order, either increasing or decreasing. When you add a new element, you remove elements from the back that violate the sorted property. When the front element leaves your window, you remove it from the front.
This gives you the min or max at the front in time. Total cost for operations is because each element enters and leaves the deque at most once.