14343 - 2024_IDS_Spring_Quiz3_Digging Pits   

Description

DGL enjoys digging pits in a courtyard and filling them with water to create water pits. The courtyard is represented as a N x M matrix where each cell can be either a dirt mound "0" or a water pit "1". Water pit cells connected in any of the four directions (up, down, left, right) form a single water pit.

Your task is to:

  1. Count the number of water pits.
  2. Find the size of the largest water pit.

DGL will also specify changes to turn water pits into dirt mounds K times. Each change might disconnect water pits, affecting their size and count. You need to calculate the number of water pits and the largest water pit size after each change.

Input

The first line contains three integers N, M, and K.

The next N lines contain M integers (0, 1), representing the initial courtyard.

The next K lines contains 2 integers x, y, pair (x, y) representing a position to turn from a water pit into a dirt mound. Each specified position is guaranteed to be a water pit initially.

  • 1 ≤ N * M ≤ 106
  • 1 ≤ K ≤ N * M
  • 1 ≤ x ≤ N
  • 1 ≤ y ≤ M

Subtask

For testcases 1 ~ 2: guarantee that N = 1.

Output

You need to print K + 1 line.

For the initial courtyard and each change, output two integers in one line seperate by a space:

  1. The size of the largest water pit after the change.
  2. The number of water pits after the change.

Sample Input  Download

Sample Output  Download

Tags




Discuss