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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cout << *i << " ";
  cout << endl;
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<double, int> P;

int main() {
  int N;
  int casenum = 1;
  while (cin >> N && N) {
    printf("%d ", casenum++);
    map<double, vector<P>> eventx;
    map<double, vector<P>> delx;
    set<double> searchx;
    REP(i, N) {
      double x, y, d;
      cin >> x >> y >> d;
      searchx.insert(x - d);
      searchx.insert(x + d);
      eventx[x - d].push_back(P(y - d, 1));
      eventx[x - d].push_back(P(y + d, -1));
      delx[x + d].push_back(P(y - d, 1));
      delx[x + d].push_back(P(y + d, -1));
    }
    vector<P> evs;
    // set<P> evs;
    double bfx = 0;
    double bfy = 0;
    double ans = 0;
    FORIT(sx, searchx) {
      ans += (*sx - bfx) * bfy;
      if (eventx.count(*sx)) {
        FORIT(it, eventx[*sx]) evs.push_back(*it);
      }
      if (delx.count(*sx)) {
        FORIT(it, delx[*sx]) {
          vector<P>::iterator findit = find(evs.begin(), evs.end(), *it);
          assert(findit != evs.end());
          evs.erase(findit);
        }
      }
      sort(evs.begin(), evs.end());
      bfx = *sx;
      bfy = 0;
      int cnt = 0;
      double ty = 0;
      FORIT(event, evs) {
        if (cnt > 0) {
          bfy += abs(event->first - ty);
        }
        ty = event->first;
        cnt += event->second;
      }
    }
    printf("%.2lf\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cout << *i << " ";
  cout << endl;
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<double, int> P;

int main() {
  int N;
  int casenum = 1;
  while (cin >> N && N) {
    printf("%d ", casenum++);
    map<double, vector<P>> eventx;
    map<double, vector<P>> delx;
    set<double> searchx;
    REP(i, N) {
      double x, y, d;
      cin >> x >> y >> d;
      searchx.insert(x - d);
      searchx.insert(x + d);
      eventx[x - d].push_back(P(y - d, 1));
      eventx[x - d].push_back(P(y + d, -1));
      delx[x + d].push_back(P(y - d, 1));
      delx[x + d].push_back(P(y + d, -1));
    }
    vector<P> evs;
    // set<P> evs;
    double bfx = 0;
    double bfy = 0;
    double ans = 0;
    FORIT(sx, searchx) {
      ans += (*sx - bfx) * bfy;
      if (delx.count(*sx)) {
        FORIT(it, delx[*sx]) {
          vector<P>::iterator findit = find(evs.begin(), evs.end(), *it);
          assert(findit != evs.end());
          evs.erase(findit);
        }
      }
      if (eventx.count(*sx)) {
        FORIT(it, eventx[*sx]) evs.push_back(*it);
      }
      sort(evs.begin(), evs.end());
      bfx = *sx;
      bfy = 0;
      int cnt = 0;
      double ty = 0;
      FORIT(event, evs) {
        if (cnt > 0) {
          bfy += abs(event->first - ty);
        }
        ty = event->first;
        cnt += event->second;
      }
    }
    printf("%.2lf\\n", ans);
  }
  return 0;
}