Problem p04000 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
// #define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
  for (int i = 0; i < A.size(); i++)
    os << A[i] << " ";
  os << endl;
  return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
  int N = A.size();
  int M;
  if (N > 0)
    M = A[0].size();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++)
      os << A[i][j] << " ";
    os << endl;
  }
  return os;
}

typedef pair<int, int> pii;
typedef long long ll;

struct edge {
  int from, to, d, c;
  edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
    from = _from;
    to = _to;
    d = _d;
    c = _c;
  }
  bool operator<(const edge &rhs) const {
    return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
  }
};

typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
  int to, cap, rev, cost;
  flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
      : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template <typename T, typename U> bool chmin(T &x, const U &y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

struct initializer {
  initializer() { cout << fixed << setprecision(11); }
};
initializer _____;
int compress(vector<int> &x1, int W) {
  vector<int> xs;
  int N = x1.size();
  for (int i = 0; i < N; i++) {
    for (int d = -2; d <= 2; d++) {
      int tx1 = x1[i] + d;
      if (0 <= tx1 && tx1 < W)
        xs.push_back(tx1);
    }
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < N; i++) {
    x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
  }
  return xs.size();
}
int N, M, K, T, Q;
signed main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> y(N), x(N);
  rep(i, N) {
    cin >> y[i] >> x[i];
    --y[i];
    --x[i];
  }
  H = compress(y, H);
  W = compress(x, W);
  vector<vector<int>> grid(H, vector<int>(W, 0));

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
// #define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
  for (int i = 0; i < A.size(); i++)
    os << A[i] << " ";
  os << endl;
  return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
  int N = A.size();
  int M;
  if (N > 0)
    M = A[0].size();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++)
      os << A[i][j] << " ";
    os << endl;
  }
  return os;
}

typedef pair<int, int> pii;
typedef long long ll;

struct edge {
  int from, to, d, c;
  edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
    from = _from;
    to = _to;
    d = _d;
    c = _c;
  }
  bool operator<(const edge &rhs) const {
    return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
  }
};

typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
  int to, cap, rev, cost;
  flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
      : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template <typename T, typename U> bool chmin(T &x, const U &y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

struct initializer {
  initializer() { cout << fixed << setprecision(11); }
};
initializer _____;
int compress(vector<int> &x1, int W) {
  vector<int> xs;
  int N = x1.size();
  for (int i = 0; i < N; i++) {
    for (int d = -2; d <= 2; d++) {
      int tx1 = x1[i] + d;
      if (0 <= tx1 && tx1 < W)
        xs.push_back(tx1);
    }
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < N; i++) {
    x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
  }
  return xs.size();
}
int N, M, K, T, Q;
signed main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> y(N), x(N);
  rep(i, N) {
    cin >> y[i] >> x[i];
    --y[i];
    --x[i];
  }
  map<pii, int> M;
  vector<int> ans(10, 0);
  ans[0] = (W - 2) * (H - 2);
  rep(k, N) {
    int i = y[k], j = x[k];
    for (int di = -2; di <= 0; di++)
      for (int dj = -2; dj <= 0; dj++) {
        int ni = i + di, nj = j + dj;
        if (0 <= ni && ni < H - 2 && 0 <= nj && nj < W - 2) {
          // cout << M[pii(ni, nj)] << " ";
          ans[M[pii(ni, nj)]]--;
          M[pii(ni, nj)]++;
          ans[M[pii(ni, nj)]]++;
        }
      }
    // cout << endl;
  }
  for (int i = 0; i <= 9; i++)
    cout << ans[i] << endl;
  return 0;
}