Problem p02680 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 1005

struct Line {

  ll A, B, C;
};

struct Info {
  Info() { x = y = 0; }
  Info(ll arg_x, ll arg_y) {
    x = arg_x;
    y = arg_y;
  }
  ll x, y;
};

ll N, M;
ll diff_row[4] = {-1, 0, 0, 1}, diff_col[4] = {0, -1, 1, 0};
Line tate[SIZE], yoko[SIZE];
map<ll, ll> mapX, mapY;
short table[4 * SIZE][4 * SIZE];

int main() {

  scanf("%lld %lld", &N, &M);

  vector<ll> X, Y;
  X.push_back(0);
  Y.push_back(0);

  // 縦線
  for (int i = 0; i < N; i++) {

    scanf("%lld %lld %lld", &tate[i].A, &tate[i].B, &tate[i].C);

    X.push_back(tate[i].A);
    X.push_back(tate[i].B);
    Y.push_back(tate[i].C);
  }

  // 横線
  for (int i = 0; i < M; i++) {

    scanf("%lld %lld %lld", &yoko[i].A, &yoko[i].B, &yoko[i].C);

    X.push_back(yoko[i].A);
    Y.push_back(yoko[i].B);
    Y.push_back(yoko[i].C);
  }

  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());

  for (ll i = 0; i < X.size(); i++) {

    mapX[X[i]] = i;
  }
  for (ll i = 0; i < Y.size(); i++) {

    mapY[Y[i]] = i;
  }

  ll H = X.size() * 2; // 偶数行が、ダミー
  ll W = Y.size() * 2; // 偶数列が、ダミー

  for (int row = 0; row < H; row++) {
    for (int col = 0; col < W; col++) {

      table[row][col] = 0;
    }
  }

  for (int i = 0; i < N; i++) {

    ll a = mapX[tate[i].A] * 2;
    ll b = mapX[tate[i].B] * 2;
    ll c = mapY[tate[i].C] * 2;
    for (ll x = a; x <= b; x++) {

      table[x][c] = -1;
    }
  }
  for (int i = 0; i < M; i++) {

    ll a = mapX[yoko[i].A] * 2;
    ll b = mapY[yoko[i].B] * 2;
    ll c = mapY[yoko[i].C] * 2;

    for (int y = b; y <= c; y++) {

      table[a][y] = -1;
    }
  }

  queue<Info> Q;
  ll start_x = mapX[0] * 2;
  ll start_y = mapY[0] * 2;
  table[start_x][start_y] = 1;

  Q.push(Info(start_x, start_y));

  Info info;

  while (!Q.empty()) {

    info = Q.front();
    Q.pop();

    for (int i = 0; i < 4; i++) {

      ll adj_x = info.x + diff_row[i];
      ll adj_y = info.y + diff_col[i];

      if (adj_x < 0 || adj_x >= H)
        continue;
      if (adj_y < 0 || adj_y >= W)
        continue;
      if (table[adj_x][adj_y] != 0)
        continue;

      table[adj_x][adj_y] = 1;

      Q.push(Info(adj_x, adj_y));
    }
  }

  ll ans = 0;

  for (ll row = 0; row < H; row++) {
    for (ll col = 0; col < W; col++) {
      if (table[row][col] != 1)
        continue;

      if (row == 0 || row == H - 1 || col == 0 || col == W - 1) {

        printf("INF\n");
        return 0;
      }
      if (row % 2 == 0 || col % 2 == 0)
        continue;

      ll tmp_x = X[row / 2 + 1] - X[row / 2];
      ll tmp_y = Y[col / 2 + 1] - Y[col / 2];

      ans += tmp_x * tmp_y;
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 2005

struct Line {

  ll A, B, C;
};

struct Info {
  Info() { x = y = 0; }
  Info(ll arg_x, ll arg_y) {
    x = arg_x;
    y = arg_y;
  }
  ll x, y;
};

ll N, M;
ll diff_row[4] = {-1, 0, 0, 1}, diff_col[4] = {0, -1, 1, 0};
Line tate[SIZE], yoko[SIZE];
map<ll, ll> mapX, mapY;
short table[4 * SIZE][4 * SIZE];

int main() {

  scanf("%lld %lld", &N, &M);

  vector<ll> X, Y;
  X.push_back(0);
  Y.push_back(0);

  // 縦線
  for (int i = 0; i < N; i++) {

    scanf("%lld %lld %lld", &tate[i].A, &tate[i].B, &tate[i].C);

    X.push_back(tate[i].A);
    X.push_back(tate[i].B);
    Y.push_back(tate[i].C);
  }

  // 横線
  for (int i = 0; i < M; i++) {

    scanf("%lld %lld %lld", &yoko[i].A, &yoko[i].B, &yoko[i].C);

    X.push_back(yoko[i].A);
    Y.push_back(yoko[i].B);
    Y.push_back(yoko[i].C);
  }

  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());

  for (ll i = 0; i < X.size(); i++) {

    mapX[X[i]] = i;
  }
  for (ll i = 0; i < Y.size(); i++) {

    mapY[Y[i]] = i;
  }

  ll H = X.size() * 2; // 偶数行が、ダミー
  ll W = Y.size() * 2; // 偶数列が、ダミー

  for (int row = 0; row < H; row++) {
    for (int col = 0; col < W; col++) {

      table[row][col] = 0;
    }
  }

  for (int i = 0; i < N; i++) {

    ll a = mapX[tate[i].A] * 2;
    ll b = mapX[tate[i].B] * 2;
    ll c = mapY[tate[i].C] * 2;
    for (ll x = a; x <= b; x++) {

      table[x][c] = -1;
    }
  }
  for (int i = 0; i < M; i++) {

    ll a = mapX[yoko[i].A] * 2;
    ll b = mapY[yoko[i].B] * 2;
    ll c = mapY[yoko[i].C] * 2;

    for (int y = b; y <= c; y++) {

      table[a][y] = -1;
    }
  }

  queue<Info> Q;
  ll start_x = mapX[0] * 2;
  ll start_y = mapY[0] * 2;
  table[start_x][start_y] = 1;

  Q.push(Info(start_x, start_y));

  Info info;

  while (!Q.empty()) {

    info = Q.front();
    Q.pop();

    for (int i = 0; i < 4; i++) {

      ll adj_x = info.x + diff_row[i];
      ll adj_y = info.y + diff_col[i];

      if (adj_x < 0 || adj_x >= H)
        continue;
      if (adj_y < 0 || adj_y >= W)
        continue;
      if (table[adj_x][adj_y] != 0)
        continue;

      table[adj_x][adj_y] = 1;

      Q.push(Info(adj_x, adj_y));
    }
  }

  ll ans = 0;

  for (ll row = 0; row < H; row++) {
    for (ll col = 0; col < W; col++) {
      if (table[row][col] != 1)
        continue;

      if (row == 0 || row == H - 1 || col == 0 || col == W - 1) {

        printf("INF\n");
        return 0;
      }
      if (row % 2 == 0 || col % 2 == 0)
        continue;

      ll tmp_x = X[row / 2 + 1] - X[row / 2];
      ll tmp_y = Y[col / 2 + 1] - Y[col / 2];

      ans += tmp_x * tmp_y;
    }
  }

  printf("%lld\n", ans);

  return 0;
}