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

#include <bits/stdc++.h>
#define PB push_back
#define MP make pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll << 60;

int N, K;
int W, H, D;
int X1[55], Y1[55], Z1[55], X2[55], Y2[55], Z2[55];
int cx1[55], cy1[55], cz1[55], cx2[55], cy2[55], cz2[55];
vector<long long int> X, Y, Z;
char fld[51 * 6][51 * 6][51 * 6];

long long int ans;
vector<int> xs;

void compress(vector<long long int> &X, int *x1, int *x2, int *vx1, int *vx2,
              int w, int *P) {
  xs.clear();
  for (int i = 0; i < N; ++i) {
    x1[i] = vx1[i];
    x2[i] = vx2[i];
  }
  for (int i = 0; i < N; ++i) {
    for (int d = -1; d <= 1; ++d) {
      int tx1 = x1[i] + d;
      int tx2 = x2[i] + d;
      if (0 <= tx1 && tx1 <= w)
        xs.PB(tx1);
      if (0 <= tx2 && tx2 <= w)
        xs.PB(tx2);
    }
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < N; ++i) {
    x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
    x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
  }
  // for(int i=0;i<xs.size();++i)cout<<xs[i]<<endl;
  for (int i = 0; i < xs.size(); ++i) {
    X.PB(xs[i + 1] - xs[i]);
  }
  *P = xs.size();
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i)
    cin >> X1[i] >> Y1[i] >> Z1[i] >> X2[i] >> Y2[i] >> Z2[i];
  compress(X, cx1, cx2, X1, X2, 1000000, &W);
  compress(Y, cy1, cy2, Y1, Y2, 1000000, &H);
  compress(Z, cz1, cz2, Z1, Z2, 1000000, &D);
  for (int i = 0; i < N; ++i) {
    for (int z = cz1[i]; z < cz2[i]; ++z) {
      for (int y = cy1[i]; y < cy2[i]; ++y) {
        for (int x = cx1[i]; x < cx2[i]; ++x) {
          fld[z][y][x]++;
        }
      }
    }
  }
  for (int z = 0; z <= D; ++z) {
    for (int y = 0; y <= H; ++y) {
      for (int x = 0; x <= W; ++x) {
        if (fld[z][y][x] >= K)
          ans += X[x] * Y[y] * Z[z];
      }
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define PB push_back
#define MP make pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll << 60;

int N, K;
int W, H, D;
int X1[55], Y1[55], Z1[55], X2[55], Y2[55], Z2[55];
int cx1[55], cy1[55], cz1[55], cx2[55], cy2[55], cz2[55];
vector<int> X, Y, Z;
unsigned short fld[50 * 6][50 * 6][50 * 6];

int ans;
vector<int> xs;

void compress(vector<int> &X, int *x1, int *x2, int *vx1, int *vx2, int w,
              int *P) {
  xs.clear();
  for (int i = 0; i < N; ++i) {
    x1[i] = vx1[i];
    x2[i] = vx2[i];
  }
  for (int i = 0; i < N; ++i) {
    for (int d = -1; d <= 1; ++d) {
      int tx1 = x1[i] + d;
      int tx2 = x2[i] + d;
      if (0 <= tx1 && tx1 <= w)
        xs.PB(tx1);
      if (0 <= tx2 && tx2 <= w)
        xs.PB(tx2);
    }
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < N; ++i) {
    x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
    x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
  }
  // for(int i=0;i<xs.size();++i)cout<<xs[i]<<endl;
  for (int i = 0; i < xs.size(); ++i) {
    X.PB(xs[i + 1] - xs[i]);
  }
  *P = xs.size();
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i)
    cin >> X1[i] >> Y1[i] >> Z1[i] >> X2[i] >> Y2[i] >> Z2[i];
  compress(X, cx1, cx2, X1, X2, 1000000, &W);
  compress(Y, cy1, cy2, Y1, Y2, 1000000, &H);
  compress(Z, cz1, cz2, Z1, Z2, 1000000, &D);
  for (int i = 0; i < N; ++i) {
    for (int z = cz1[i]; z < cz2[i]; ++z) {
      for (int y = cy1[i]; y < cy2[i]; ++y) {
        for (int x = cx1[i]; x < cx2[i]; ++x) {
          fld[z][y][x]++;
        }
      }
    }
  }
  for (int z = 0; z <= D; ++z) {
    for (int y = 0; y <= H; ++y) {
      for (int x = 0; x <= W; ++x) {
        if (fld[z][y][x] >= K)
          ans += X[x] * Y[y] * Z[z];
      }
    }
  }

  // cout<<W<<" "<<H<<" "<<D<<endl;
  cout << ans << endl;
}