Problem p02680 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n) for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

struct L {
  int64_t s;
  int64_t g;
  int64_t l;
};

vector<int64_t> xss(10000);
vector<int64_t> yss(10000);

vector<vector<bool>> v_map(10000, vector<bool>(10000));
vector<vector<bool>> h_map(10000, vector<bool>(10000));
vector<vector<bool>> s_map(10000, vector<bool>(10000));

int64_t solve(int sxidx, int syidx) {
  queue<pair<int, int>> s;
  s.push({sxidx, syidx});
  int64_t ans = 0;

  while (!s.empty()) {
    auto it = s.front();
    int xidx = it.first;
    int yidx = it.second;
    s.pop();

    if (xidx == 0 || xidx == xss.size() || yidx == 0 || yidx == yss.size()) {
      return -1;
    }
    if (s_map[xidx][yidx])
      continue;
    s_map[xidx][yidx] = 1;

    ans += (xss[xidx] - xss[xidx - 1]) * (yss[yidx] - yss[yidx - 1]);
    if (!h_map[xidx - 1][yidx - 1]) {
      s.push({xidx - 1, yidx});
    }
    if (!h_map[xidx][yidx - 1]) {
      s.push({xidx + 1, yidx});
    }
    if (!v_map[xidx - 1][yidx - 1]) {
      s.push({xidx, yidx - 1});
    }
    if (!v_map[xidx - 1][yidx]) {
      s.push({xidx, yidx + 1});
    }
  }

  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(20);

  int n, m;
  cin >> n >> m;

  vector<L> vs(n);
  vector<L> hs(m);

  {
    int nx = 0;
    int ny = 0;
    FOR_LT(i, 0, n) {
      int64_t a, b, c;
      cin >> a >> b >> c;
      xss[nx++] = a;
      xss[nx++] = b;
      yss[ny++] = c;
      vs[i] = {a, b, c};
    }
    FOR_LT(j, 0, m) {
      int64_t a, b, c;
      cin >> c >> a >> b;
      yss[ny++] = a;
      yss[ny++] = b;
      xss[nx++] = c;
      hs[j] = {a, b, c};
    }

    sort(xss.begin(), xss.end());
    {
      auto it = unique(xss.begin(), xss.end());
      xss.erase(it, xss.end());
    }
    sort(yss.begin(), yss.end());
    {
      auto it = unique(yss.begin(), yss.end());
      yss.erase(it, yss.end());
    }
  }

  for (auto &v : vs) {
    int yidx = std::lower_bound(yss.begin(), yss.end(), v.l) - yss.begin();
    int sidx = std::lower_bound(xss.begin(), xss.end(), v.s) - xss.begin();
    int gidx = std::lower_bound(xss.begin(), xss.end(), v.g) - xss.begin();
    FOR_LT(i, sidx, gidx) { v_map[i][yidx] = 1; }
  }

  for (auto &h : hs) {
    int xidx = std::lower_bound(xss.begin(), xss.end(), h.l) - xss.begin();
    int sidx = std::lower_bound(yss.begin(), yss.end(), h.s) - yss.begin();
    int gidx = std::lower_bound(yss.begin(), yss.end(), h.g) - yss.begin();
    FOR_LT(i, sidx, gidx) { h_map[xidx][i] = 1; }
  }

  int xidx = std::lower_bound(xss.begin(), xss.end(), 0) - xss.begin();
  int yidx = std::lower_bound(yss.begin(), yss.end(), 0) - yss.begin();

  int64_t ans = solve(xidx, yidx);
  if (ans == -1) {
    cout << "INF" << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n) for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

struct L {
  int64_t s;
  int64_t g;
  int64_t l;
};

vector<int64_t> xss(10000);
vector<int64_t> yss(10000);

vector<vector<bool>> v_map(10000, vector<bool>(10000));
vector<vector<bool>> h_map(10000, vector<bool>(10000));
vector<vector<bool>> s_map(10000, vector<bool>(10000));

int64_t solve(int xidx, int yidx) {
  if (xidx == 0 || xidx == xss.size() || yidx == 0 || yidx == yss.size()) {
    return -1;
  }
  if (s_map[xidx][yidx])
    return 0;
  s_map[xidx][yidx] = 1;

  int64_t ans = (xss[xidx] - xss[xidx - 1]) * (yss[yidx] - yss[yidx - 1]);
  if (!h_map[xidx - 1][yidx - 1]) {
    int64_t c = solve(xidx - 1, yidx);
    if (c == -1)
      return -1;
    ans += c;
  }
  if (!h_map[xidx][yidx - 1]) {
    int64_t c = solve(xidx + 1, yidx);
    if (c == -1)
      return -1;
    ans += c;
  }
  if (!v_map[xidx - 1][yidx - 1]) {
    int64_t c = solve(xidx, yidx - 1);
    if (c == -1)
      return -1;
    ans += c;
  }
  if (!v_map[xidx - 1][yidx]) {
    int64_t c = solve(xidx, yidx + 1);
    if (c == -1)
      return -1;
    ans += c;
  }

  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(20);

  int n, m;
  cin >> n >> m;

  vector<L> vs(n);
  vector<L> hs(m);

  {
    int nx = 0;
    int ny = 0;
    FOR_LT(i, 0, n) {
      int64_t a, b, c;
      cin >> a >> b >> c;
      xss[nx++] = a;
      xss[nx++] = b;
      yss[ny++] = c;
      vs[i] = {a, b, c};
    }
    FOR_LT(j, 0, m) {
      int64_t a, b, c;
      cin >> c >> a >> b;
      yss[ny++] = a;
      yss[ny++] = b;
      xss[nx++] = c;
      hs[j] = {a, b, c};
    }

    sort(xss.begin(), xss.end());
    {
      auto it = unique(xss.begin(), xss.end());
      xss.erase(it, xss.end());
    }
    sort(yss.begin(), yss.end());
    {
      auto it = unique(yss.begin(), yss.end());
      yss.erase(it, yss.end());
    }
  }

  for (auto &v : vs) {
    int yidx = std::lower_bound(yss.begin(), yss.end(), v.l) - yss.begin();
    int sidx = std::lower_bound(xss.begin(), xss.end(), v.s) - xss.begin();
    int gidx = std::lower_bound(xss.begin(), xss.end(), v.g) - xss.begin();
    FOR_LT(i, sidx, gidx) { v_map[i][yidx] = 1; }
  }

  for (auto &h : hs) {
    int xidx = std::lower_bound(xss.begin(), xss.end(), h.l) - xss.begin();
    int sidx = std::lower_bound(yss.begin(), yss.end(), h.s) - yss.begin();
    int gidx = std::lower_bound(yss.begin(), yss.end(), h.g) - yss.begin();
    FOR_LT(i, sidx, gidx) { h_map[xidx][i] = 1; }
  }

  int xidx = std::lower_bound(xss.begin(), xss.end(), 0) - xss.begin();
  int yidx = std::lower_bound(yss.begin(), yss.end(), 0) - yss.begin();

  int64_t ans = solve(xidx, yidx);
  if (ans == -1) {
    cout << "INF" << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}