Yasser's Medians
Practice
3.5 (2 votes)
Data structures
Binary indexed tree
Datastructures
Advanced data structures
Fenwick (binary indexed) trees
Problem
33% Success 471 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Given \(N\) numbers and an integer \(K\) find :

\((N^{maxmed}) mod 1e9+7\)

Formally: we can define \(maxmed\) as the maximum median of each subarray of length \(K\).

Note that: the median of \(K\) numbers indexed from \(1\) is \({((K+1)/2)^{th}}\) smallest of them, rounding down for even \(K\).

 

Input format

  • The first line contains two integers \(N\) and \(K\) denoting the number of elements and size of the subarray.
  • The second line contains \(N\) space-separated integers.

Output format

Print the answer as described above.

Constraints

\(2 \le N,K \le 10^5\)

\(1 \le a_i \le 10^5\)

\(K \le N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
2 votes
Tags:
AlgorithmsApprovedBit ManipulationFenwick treeHardOpenTrees
Points:50
1 votes
Tags:
Advanced Data StructuresData StructuresDepth First SearchFenwick TreeFenwick treeHardOpentreap
Points:50
4 votes
Tags:
AlgorithmsApprovedBit ManipulationFenwick treeHardOpenTrees