PlayerUnknown's Battlegrounds
Time limit1.5sMemory limit256 MB
For each value x, count the subgrids whose minimum equals x, given an n by m grid holding a permutation of 1 to n*m.
- Level
Hard8 of 10
- Topics
- Divide and conquer, Implementation, Brute force, Math
- Solved
- No attempts yet
Problem
When Rikka was playing PUBG (PlayerUnknown's Battlegrounds), she could not win the game. So this time she decided to use some techniques. With the techniques, Rikka can now see clearly where all players are in the game.
In the game, the map can be denoted as a grid of size . Rikka uses software that can rate an enemy's combat value based on their performance. Right now there is exactly one enemy in each square, and all enemies' combat values form a permutation of the integers from to . Since Rikka is quite a green hand, she always cares about the weakest enemies (the less an enemy's combat value is, the weaker the enemy is).
We denote the square at row , column as . A subgrid can be defined by , where and , and the subgrid itself is the squares for which and . Two subgrids and are the same if and only if .
For now, Rikka wants to know how many subgrids are there such that the weakest enemy's combat value in them is equal to . Help her find the answers for all .
Input
The first line of input contains two integers and ().
Then follow lines. The -th of them contains integers, where the -th integer is the combat value of the enemy in . It is guaranteed that the values form a permutation of the integers from to .
Output
Print lines, with one integer on each line.
The integer on the -th line is the answer for .