#B3662. Mountain Peaks After Land Swaps
Mountain Peaks After Land Swaps
Mountain Peaks After Land Swaps
In Berland Kingdom, the land is represented as an grid. The cell at row and column initially has an altitude of . Over a long period, there are geological events. In each event, the altitudes of two specified cells are swapped.
A cell is called a mountain peak if its altitude is strictly greater than the altitudes of all its directly adjacent neighbors (up, down, left, and right; if a neighbor does not exist, it is ignored).
After all swaps, you are to determine how many mountain peaks exist and output their coordinates. The cells are indexed starting from 1.
inputFormat
The first line contains three integers , , and (, ), representing the number of rows, columns, and the number of swap events respectively.
The next lines each contain integers, where the -th integer in the -th line is , the altitude of the cell at row , column .
Then lines follow, each containing four integers , , , , indicating that the altitudes of the cells at positions and are to be swapped.
outputFormat
Output the total number of mountain peaks in the grid after all swaps. Then, output the coordinates of each mountain peak in separate lines in the format row column
. The order of peaks can be arbitrary.
sample
3 3 0
1 2 3
1 4 2
1 1 2
2
1 3
2 2
</p>