Square Queries
Time limit4.5sMemory limit1024 MB
For each query, count the distinct values still present in the grid after blanking out the K by K square with the given top-left corner.
- Level
Medium6 of 10
- Topics
- Hash map, Prefix sum, Array
- Solved
- No attempts yet
Problem
There is a grid with rows and columns. Each cell is denoted , meaning the cell in row from the top and column from the left. Cell contains an integer , and each value satisfies .
An integer and queries are given. Each query gives coordinates , which denote a square with its top-left cell at and side length . For each query, erase the numbers in the cells inside the given square, then count the distinct numbers in the remaining cells of the grid.
All queries are independent. A previous query does not affect the next one.
Input
The first line contains , , , and . (, , )
The next lines each contain integers , separated by spaces. ()
The next lines each contain two integers and , the top-left cell of the square. (, )
Output
For each query, print on its own line the number of distinct values in the grid that remain after removing the given square.