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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> xs, ys, zs;
  map<int, int> xp, yp, zp;
  int x1[60], x2[60], y1[60], y2[60], z1[60], z2[60], xm[110], ym[110], zm[110];
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d%d%d%d%d%d", &x1[i], &y1[i], &z1[i], &x2[i], &y2[i], &z2[i]);
    xs.push_back(x1[i]);
    xs.push_back(x2[i]);
    ys.push_back(y1[i]);
    ys.push_back(y2[i]);
    zs.push_back(z1[i]);
    zs.push_back(z2[i]);
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  sort(zs.begin(), zs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  zs.erase(unique(zs.begin(), zs.end()), zs.end());

  for (int i = 0; i < 2 * N; ++i) {
    if (xs.size() > i) {
      xm[i] = xs[i];
      xp[xs[i]] = i;
    }
    if (ys.size() > i) {
      ym[i] = ys[i];
      yp[ys[i]] = i;
    }
    if (zs.size() > i) {
      zm[i] = zs[i];
      zp[zs[i]] = i;
    }
  }
  int cnt[110][110][110] = {0};
  for (int i = 0; i < N; ++i)
    for (int j = xp[x1[i]]; j < xp[x2[i]]; ++j)
      for (int k = yp[y1[i]]; k < yp[y2[i]]; ++k)
        for (int l = zp[z1[i]]; l < zp[z2[i]]; ++l)
          cnt[j][k][l]++;

  for (int i = 0; i < xs.size() - 1; ++i)
    for (int j = 0; j < ys.size() - 1; ++j)
      for (int k = 0; k < zs.size() - 1; ++k)
        if (cnt[i][j][k] >= K)
          ans += ((ll)(xm[i + 1] - xm[i]) * (ll)(ym[j + 1] - ym[j]) *
                  (zm[k + 1] - zm[k]));

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> xs, ys, zs;
  map<ll, int> xp, yp, zp;
  ll x1[60], x2[60], y1[60], y2[60], z1[60], z2[60], xm[60], ym[60], zm[60],
      ans = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%lld%lld%lld%lld%lld%lld", &x1[i], &y1[i], &z1[i], &x2[i], &y2[i],
          &z2[i]);
    xs.push_back(x1[i]);
    xs.push_back(x2[i]);
    ys.push_back(y1[i]);
    ys.push_back(y2[i]);
    zs.push_back(z1[i]);
    zs.push_back(z2[i]);
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  sort(zs.begin(), zs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  zs.erase(unique(zs.begin(), zs.end()), zs.end());

  for (int i = 0; i < 2 * N; ++i) {
    if (xs.size() > i) {
      xm[i] = xs[i];
      xp[xs[i]] = i;
    }
    if (ys.size() > i) {
      ym[i] = ys[i];
      yp[ys[i]] = i;
    }
    if (zs.size() > i) {
      zm[i] = zs[i];
      zp[zs[i]] = i;
    }
  }
  int cnt[60][60][60] = {0};
  for (int i = 0; i < N; ++i)
    for (int j = xp[x1[i]]; j < xp[x2[i]]; ++j)
      for (int k = yp[y1[i]]; k < yp[y2[i]]; ++k)
        for (int l = zp[z1[i]]; l < zp[z2[i]]; ++l)
          cnt[j][k][l]++;

  for (int i = 0; i < xs.size() - 1; ++i)
    for (int j = 0; j < ys.size() - 1; ++j)
      for (int k = 0; k < zs.size() - 1; ++k)
        if (cnt[i][j][k] >= K)
          ans += ((ll)(xm[i + 1] - xm[i]) * (ym[j + 1] - ym[j]) *
                  (zm[k + 1] - zm[k]));

  cout << ans << endl;
  return 0;
}