Problem p04000 (C++)

Buggy submission (status: Time Limit Exceeded):
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repl(i, a, b) for (ll i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = b; i >= (a); --i)
#define repdl(i, a, b) for (ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename H> bool chmin(H &v1, const H v2) {
  if (v1 > v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H> bool chmax(H &v1, const H v2) {
  if (v1 < v2) {
    v1 = v2;
    return true;
  }
  return false;
}
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template <typename H> void read(H &head) { cin >> head; }
template <typename H, typename... T> void read(H &head, T &...tail) {
  cin >> head;
  read(tail...);
}
template <typename H> void write(H head) { cout << head << '\n'; }
template <typename H, typename... T> void write(H head, T... tail) {
  cout << head << " ";
  write(tail...);
}
template <typename... T> void die(T... tok) {
  write(tok...);
  exit(0);
}
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif
using namespace std;

namespace std {
template <typename T, typename K> struct hash<pair<T, K>> {
  size_t operator()(pair<T, K> const &p) const noexcept {
    size_t h1 = std::hash<T>{}(p.first);
    size_t h2 = std::hash<K>{}(p.second);
    return h1 ^ (h2 << 1);
  }
};
} // namespace std

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int h, w, n;
  read(h, w, n);
  unordered_map<pair<int, int>, int> mp;
  unordered_set<pair<int, int>> cons;

  mp.reserve(n * 9);
  cons.reserve(n * 9);

  rep(i, 0, n) {
    int x, y;
    read(x, y);
    mp[{x, y}] = 1;
    rep(a, -2, 1) rep(b, -2, 1) if (1 <= x + a && x + a <= h - 2 &&
                                    1 <= y + b && y + b <= w - 2)
        cons.insert({x + a, y + b});
  }

  vector<ll> ans(10);
  for (auto p : cons) {
    int x, y;
    tie(x, y) = p;
    int cnt = 0;
    rep(i, 0, 3) rep(j, 0, 3) cnt += mp[{x + i, y + j}];
    ans[cnt]++;
  }

  ans[0] = 1ll * (h - 2) * (w - 2);
  rep(i, 1, 10) ans[0] -= ans[i];

  rep(i, 0, 10) write(ans[i]);
}


Fixed submission:
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repl(i, a, b) for (ll i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = b; i >= (a); --i)
#define repdl(i, a, b) for (ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename H> bool chmin(H &v1, const H v2) {
  if (v1 > v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H> bool chmax(H &v1, const H v2) {
  if (v1 < v2) {
    v1 = v2;
    return true;
  }
  return false;
}
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template <typename H> void read(H &head) { cin >> head; }
template <typename H, typename... T> void read(H &head, T &...tail) {
  cin >> head;
  read(tail...);
}
template <typename H> void write(H head) { cout << head << '\n'; }
template <typename H, typename... T> void write(H head, T... tail) {
  cout << head << " ";
  write(tail...);
}
template <typename... T> void die(T... tok) {
  write(tok...);
  exit(0);
}
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif
using namespace std;

namespace std {
template <typename T, typename K> struct hash<pair<T, K>> {
  size_t operator()(pair<T, K> const &p) const noexcept {
    size_t h1 = std::hash<T>{}(p.first);
    size_t h2 = std::hash<K>{}(p.second);
    return h1 ^ (h2 << 1);
  }
};
} // namespace std

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int h, w, n;
  read(h, w, n);
  map<pair<int, int>, int> mp;
  set<pair<int, int>> cons;

  rep(i, 0, n) {
    int x, y;
    read(x, y);
    mp[{x, y}] = 1;
    rep(a, -2, 1) rep(b, -2, 1) if (1 <= x + a && x + a <= h - 2 &&
                                    1 <= y + b && y + b <= w - 2)
        cons.insert({x + a, y + b});
  }

  vector<ll> ans(10);
  for (auto p : cons) {
    int x, y;
    tie(x, y) = p;
    int cnt = 0;
    rep(i, 0, 3) rep(j, 0, 3) cnt += mp[{x + i, y + j}];
    ans[cnt]++;
  }

  ans[0] = 1ll * (h - 2) * (w - 2);
  rep(i, 1, 10) ans[0] -= ans[i];

  rep(i, 0, 10) write(ans[i]);
}