Problem:
Score : 400 points

Problem Statement

We have a grid with H rows and W columns. At first, all cells were painted white.

Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.

Compute the following:

For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

Constraints

3 \leq H \leq 10^9

3 \leq W \leq 10^9

0 \leq N \leq min(10^5,H×W)

1 \leq a_i \leq H (1 \leq i \leq N)

1 \leq b_i \leq W (1 \leq i \leq N)

(a_i, b_i) \neq (a_j, b_j) (i \neq j)

Input

The input is given from Standard Input in the following format:

H W N
a_1 b_1
:
a_N b_N

Output

Print 10 lines.
The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.

Sample Input 1

4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4

Sample Output 1

0
0
0
2
4
0
0
0
0
0

There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.

Sample Input 2

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

Sample Output 2

4
26
22
10
2
0
0
0
0
0

Sample Input 3

1000000000 1000000000 0

Sample Output 3

999999996000000004
0
0
0
0
0
0
0
0
0

Solution in C++ (Clang 10.0.0) (judge verdict: Time Limit Exceeded)


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <bitset>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

struct node {
  int v;
  int supply;
  int amari;
};

class MyComparison {
public:
  bool operator()(node n1, node n2) {
    return (n1.supply!=n2.supply)?(n1.supply>n2.supply):(n1.amari<n2.amari);
  }
};

int main() {
  int H, W, N;
  std::cin >> H >> W >> N;
  std::vector<int > a(N), b(N);
  std::set<int> point[100004];
  //std::set<int> point[100];
  std::set<int > row;
  std::map<int, int > indexmap;
  std::set<std::pair<int, int > > square;
  for (int i=0; i<N; i++) {
    std::cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    row.insert(a[i]);
  }
  int counter = 0;
  for (int s : row) {
    indexmap[s] = counter;
    counter++;
  }
  for (int i=0; i<N; i++) {
    point[indexmap[a[i]]].insert(b[i]);
  }
  while(true){}
  std::vector<long long > cnt(10, 0);
  for (int r : row) {
    for (int c : point[r]) {
      for (int rr = std::max(1, r-1); rr<=std::min(H-2, r+1); rr++) {
        for (int cc = std::max(1, c-1); cc<=std::min(W-2, c+1); cc++) {
          square.insert(std::make_pair(rr,cc));
        }
      }
    }
  }
  for (auto entry: square) {
    int r = entry.first;
    int c = entry.second;
    //printf("checking (%d, %d)\n", r, c);
    int num = 0;
    for (int rr = r-1; rr<=r+1; rr++) {
      for (int cc = c-1; cc<=c+1; cc++) {
        if (row.find(rr)!=row.end()) {
          if (point[indexmap[rr]].find(cc)!=point[indexmap[rr]].end()) {
            num++;
          }
        }
      }
    }
    cnt[num]++;
  }

  long long nonzero_sum = 0;
  for (int i=1; i<=9; i++) {
    nonzero_sum += cnt[i];
  }
  cnt[0] = (long long)(H-2)*(W-2)-nonzero_sum;
  for (int i=0; i<=9; i++) {
    std::cout << cnt[i] << std::endl;
  }
  return 0;
}