Quality of Living

Source: IOI 2010 (Day 1, Task 3), alternate link

  1. Read the problem and summarise the task.
  2. Propose a naive algorithm to solve the problem.
  3. Identify at least two avenues by which to potentially reduce the running time of the algorithm, and evaluate which (if any) of these might be viable.

Would this problem be easier if we were instead testing a proposed median?

  1. Consider the following related task: given the same input but also an integer T, design a function hasRectangle() which returns a boolean representing whether or not there is an H x W rectangle of median T. If this task could be solved efficiently, could we then solve the original problem efficiently too?

Now, we get to the question of testing a proposed median.

  1. Propose a target time complexity for testing a proposed median, and discuss how that work might be distributed between preprocessing and querying each subrectangle.

  2. Design an algorithm that tests a proposed median, and evaluate whether it meets the target time complexity.
  3. Implement your algorithm in code.
  4. Submit your program for judging!