Problem p00503 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
struct fish {
  int lx, ly, lz;
  int rx, ry, rz;
};
struct Compress {
  map<int, int> mp;
  map<int, int> revmp;

  Compress(vector<int> vs) {
    sort(vs.begin(), vs.end());
    vs.erase(unique(vs.begin(), vs.end()), vs.end());
    for (int i = 0; i < vs.size(); ++i) {
      mp[vs[i]] = i;
      revmp[i] = vs[i];
    }
  }
  Compress(const set<int> &vs) {
    int num = 0;
    for (auto v : vs) {
      mp[v] = num;
      revmp[num] = v;
      num++;
    }
  }
};
int pluss[101][101][101];
int num[102][102][102];
int main() {
  int N, K;
  cin >> N >> K;
  vector<fish> fs;
  vector<int> xs, ys, zs;
  for (int i = 0; i < N; ++i) {
    int lx, ly, ld, rx, ry, rd;
    cin >> lx >> ly >> ld >> rx >> ry >> rd;
    fs.push_back(fish{lx, ly, ld, rx, ry, rd});
    xs.push_back(lx);
    xs.push_back(rx);
    ys.push_back(ly);
    ys.push_back(ry);
    zs.push_back(ld);
    zs.push_back(rd);
  }
  Compress cx(xs), cy(ys), cz(zs);
  for (auto &f : fs) {
    f.lx = cx.mp[f.lx];
    f.rx = cx.mp[f.rx];
    f.ly = cy.mp[f.ly];
    f.ry = cy.mp[f.ry];
    f.lz = cz.mp[f.lz];
    f.rz = cz.mp[f.rz];
  }
  memset(pluss, 0, sizeof(pluss));
  for (auto f : fs) {
    pluss[f.lx][f.ly][f.lz]++;
    pluss[f.rx][f.ly][f.lz]--;
    pluss[f.lx][f.ry][f.lz]--;
    pluss[f.lx][f.lx][f.rz]--;
    pluss[f.rx][f.ry][f.lz]++;
    pluss[f.lx][f.ry][f.rz]++;
    pluss[f.rx][f.ly][f.rz]++;
    pluss[f.rx][f.ry][f.rz]--;
  }
  memset(num, 0, sizeof(num));
  long long int ans = 0;
  for (int x = 1; x < 102; ++x) {
    for (int y = 1; y < 102; ++y) {
      for (int z = 1; z < 102; ++z) {
        num[x][y][z] = pluss[x - 1][y - 1][z - 1] + num[x][y][z - 1] +
                       num[x][y - 1][z] + num[x - 1][y][z] -
                       num[x - 1][y - 1][z] - num[x - 1][y][z - 1] -
                       num[x][y - 1][z - 1] + num[x - 1][y - 1][z - 1];
        if (num[x][y][z] >= K) {
          if (cx.revmp.find(x) == cx.revmp.end())
            assert(false);
          if (cy.revmp.find(y) == cy.revmp.end())
            assert(false);

          if (cz.revmp.find(z) == cz.revmp.end())
            assert(false);

          long long int dx = cx.revmp[x] - cx.revmp[x - 1];
          long long int dy = cy.revmp[y] - cy.revmp[y - 1];
          long long int dz = cz.revmp[z] - cz.revmp[z - 1];
          ans += dx * dy * dz;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
struct fish {
  int lx, ly, lz;
  int rx, ry, rz;
};
struct Compress {
  map<int, int> mp;
  map<int, int> revmp;

  Compress(vector<int> vs) {
    sort(vs.begin(), vs.end());
    vs.erase(unique(vs.begin(), vs.end()), vs.end());
    for (int i = 0; i < vs.size(); ++i) {
      mp[vs[i]] = i;
      revmp[i] = vs[i];
    }
  }
  Compress(const set<int> &vs) {
    int num = 0;
    for (auto v : vs) {
      mp[v] = num;
      revmp[num] = v;
      num++;
    }
  }
};
int pluss[101][101][101];
int num[102][102][102];
int main() {
  int N, K;
  cin >> N >> K;
  vector<fish> fs;
  vector<int> xs, ys, zs;
  for (int i = 0; i < N; ++i) {
    int lx, ly, ld, rx, ry, rd;
    cin >> lx >> ly >> ld >> rx >> ry >> rd;
    fs.push_back(fish{lx, ly, ld, rx, ry, rd});
    xs.push_back(lx);
    xs.push_back(rx);
    ys.push_back(ly);
    ys.push_back(ry);
    zs.push_back(ld);
    zs.push_back(rd);
  }
  Compress cx(xs), cy(ys), cz(zs);
  for (auto &f : fs) {
    f.lx = cx.mp[f.lx];
    f.rx = cx.mp[f.rx];
    f.ly = cy.mp[f.ly];
    f.ry = cy.mp[f.ry];
    f.lz = cz.mp[f.lz];
    f.rz = cz.mp[f.rz];
  }
  memset(pluss, 0, sizeof(pluss));
  for (auto f : fs) {
    pluss[f.lx][f.ly][f.lz]++;
    pluss[f.rx][f.ly][f.lz]--;
    pluss[f.lx][f.ry][f.lz]--;
    pluss[f.lx][f.ly][f.rz]--;
    pluss[f.rx][f.ry][f.lz]++;
    pluss[f.lx][f.ry][f.rz]++;
    pluss[f.rx][f.ly][f.rz]++;
    pluss[f.rx][f.ry][f.rz]--;
  }
  memset(num, 0, sizeof(num));
  long long int ans = 0;
  for (int x = 1; x < 102; ++x) {
    for (int y = 1; y < 102; ++y) {
      for (int z = 1; z < 102; ++z) {
        num[x][y][z] = pluss[x - 1][y - 1][z - 1] + num[x][y][z - 1] +
                       num[x][y - 1][z] + num[x - 1][y][z] -
                       num[x - 1][y - 1][z] - num[x - 1][y][z - 1] -
                       num[x][y - 1][z - 1] + num[x - 1][y - 1][z - 1];
        if (num[x][y][z] >= K) {
          if (cx.revmp.find(x) == cx.revmp.end())
            assert(false);
          if (cy.revmp.find(y) == cy.revmp.end())
            assert(false);

          if (cz.revmp.find(z) == cz.revmp.end())
            assert(false);

          long long int dx = cx.revmp[x] - cx.revmp[x - 1];
          long long int dy = cy.revmp[y] - cy.revmp[y - 1];
          long long int dz = cz.revmp[z] - cz.revmp[z - 1];
          ans += dx * dy * dz;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}