C. [Policy-based data structures] Sliding Median time limit…

Written by Anonymous on June 17, 2026 in Uncategorized with no comments.

Questions

C. [Pоlicy-bаsed dаtа structures] Sliding Median time limit per test: 2 secоnds memоry limit per test: 256 megabytes You are given an array of n integers. Your task is to calculate the median of each window of k elements, from left to right. The median is the middle element when the elements are sorted. If the number of elements is even, there are two possible medians and we assume that the median is the smaller of them. Input The first line contains two integers n and k (1≤k≤n≤2⋅105) — the number of movies. The second line contains n space-separated integers xi (1≤xi≤109) — the content of the array. Output Print n-k+1 integers: the medians of all subarrays of k elements from left to right. HINTS Use indexed_set to compute the median efficiently. You can add and remove elements from indexed_set efficiently. Examples Input Output 8 32 4 3 5 8 1 2 1 3 4 5 5 2 1  

Comments are closed.