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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint inf = 1001001001;
vector<lint> x, y;
int xn, ynum;
lint a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
bool xb[3010][3010], yb[3010][3010], sumi[3010][3010];
/*void dfs(int u,int v){
        sumi[u][v]=true;
        //cout<<"("<<x[u]<<","<<y[v]<<")-("<<x[u+1]<<","<<y[v+1]<<")"<<endl;
        if(u>0 && !xb[u][v] && !sumi[u-1][v]) dfs(u-1,v);
        if(v>0 && !yb[u][v] && !sumi[u][v-1]) dfs(u,v-1);
        if(u<xn-2 && !xb[u+1][v] && !sumi[u+1][v]) dfs(u+1,v);
        if(v<ynum-2 && !yb[u][v+1] && !sumi[u][v+1]) dfs(u,v+1);
}*/
int main() {
  int n, m;
  x.pb(0);
  y.pb(0);
  x.pb(inf);
  y.pb(inf);
  x.pb(-inf);
  y.pb(-inf);
  cin >> n >> m;
  rep(i, n) {
    cin >> a[i] >> b[i] >> c[i];
    x.pb(a[i]);
    x.pb(b[i]);
    y.pb(c[i]);
  }
  rep(i, m) {
    cin >> d[i] >> e[i] >> f[i];
    x.pb(d[i]);
    y.pb(e[i]);
    y.pb(f[i]);
  }
  sort(All(x));
  x.erase(unique(All(x)), x.end());
  sort(All(y));
  y.erase(unique(All(y)), y.end());
  xn = x.size();
  ynum = y.size();
  memset(xb, false, sizeof(xb));
  memset(yb, false, sizeof(yb));
  rep(i, n) {
    int xs = lower_bound(All(x), a[i]) - x.begin();
    int xg = lower_bound(All(x), b[i]) - x.begin();
    int ys = lower_bound(All(y), c[i]) - y.begin();
    REP(j, xs, xg) yb[j][ys] = true;
  }
  rep(i, m) {
    int xs = lower_bound(All(x), d[i]) - x.begin();
    int ys = lower_bound(All(y), e[i]) - y.begin();
    int yg = lower_bound(All(y), f[i]) - y.begin();
    REP(j, ys, yg) xb[xs][j] = true;
  }
  memset(sumi, false, sizeof(sumi));
  queue<pint> q;
  q.push(mp(lower_bound(All(x), 0L) - x.begin(),
            lower_bound(All(y), 0L) - y.begin()));
  while (!q.empty()) {
    pint p = q.front();
    q.pop();
    int u = p.fi, v = p.se;
    sumi[u][v] = true;
    if (u > 0 && !xb[u][v] && !sumi[u - 1][v])
      q.push(mp(u - 1, v)), sumi[u - 1][v] = true;
    if (v > 0 && !yb[u][v] && !sumi[u][v - 1])
      q.push(mp(u, v - 1)), sumi[u][v - 1] = true;
    if (u < xn - 2 && !xb[u + 1][v] && !sumi[u + 1][v])
      q.push(mp(u + 1, v)), sumi[u + 1][v] = true;
    if (v < ynum - 2 && !yb[u][v + 1] && !sumi[u][v + 1])
      q.push(mp(u, v + 1)), sumi[u][v + 1] = true;
  }
  lint out = 0;
  rep(i, xn - 1) rep(j, ynum - 1) {
    if (sumi[i][j]) {
      if (i == 0 || j == 0 || i == xn - 2 || j == ynum - 2) {
        cout << "INF" << endl;
        return 0;
      }
      out += (x[i + 1] - x[i]) * (y[j + 1] - y[j]);
    }
  }
  // if(out>4E18L) cout<<"INF"<<endl;
  cout << out << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint inf = 1001001001;
vector<lint> x, y;
int xn, ynum;
lint a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
bool xb[3010][3010], yb[3010][3010], sumi[3010][3010];
void dfs(int u, int v) {
  sumi[u][v] = true;
  // cout<<"("<<x[u]<<","<<y[v]<<")-("<<x[u+1]<<","<<y[v+1]<<")"<<endl;
  if (u > 0 && !xb[u][v] && !sumi[u - 1][v])
    dfs(u - 1, v);
  if (v > 0 && !yb[u][v] && !sumi[u][v - 1])
    dfs(u, v - 1);
  if (u < xn - 2 && !xb[u + 1][v] && !sumi[u + 1][v])
    dfs(u + 1, v);
  if (v < ynum - 2 && !yb[u][v + 1] && !sumi[u][v + 1])
    dfs(u, v + 1);
}
int main() {
  int n, m;
  x.pb(0);
  y.pb(0);
  x.pb(inf);
  y.pb(inf);
  x.pb(-inf);
  y.pb(-inf);
  cin >> n >> m;
  rep(i, n) {
    cin >> a[i] >> b[i] >> c[i];
    x.pb(a[i]);
    x.pb(b[i]);
    y.pb(c[i]);
  }
  rep(i, m) {
    cin >> d[i] >> e[i] >> f[i];
    x.pb(d[i]);
    y.pb(e[i]);
    y.pb(f[i]);
  }
  sort(All(x));
  x.erase(unique(All(x)), x.end());
  sort(All(y));
  y.erase(unique(All(y)), y.end());
  xn = x.size();
  ynum = y.size();
  memset(xb, false, sizeof(xb));
  memset(yb, false, sizeof(yb));
  rep(i, n) {
    int xs = lower_bound(All(x), a[i]) - x.begin();
    int xg = lower_bound(All(x), b[i]) - x.begin();
    int ys = lower_bound(All(y), c[i]) - y.begin();
    REP(j, xs, xg) yb[j][ys] = true;
  }
  rep(i, m) {
    int xs = lower_bound(All(x), d[i]) - x.begin();
    int ys = lower_bound(All(y), e[i]) - y.begin();
    int yg = lower_bound(All(y), f[i]) - y.begin();
    REP(j, ys, yg) xb[xs][j] = true;
  }
  memset(sumi, false, sizeof(sumi));
  dfs(lower_bound(All(x), 0L) - x.begin(), lower_bound(All(y), 0L) - y.begin());
  lint out = 0;
  rep(i, xn - 1) rep(j, ynum - 1) {
    if (sumi[i][j])
      out += (x[i + 1] - x[i]) * (y[j + 1] - y[j]);
  }
  if (out >= inf * inf)
    cout << "INF" << endl;
  else
    cout << out << endl;
}