alexjercan/bugnet huggingface dataset:
Problem p02357 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, l, a[1111111];
  cin >> n >> l;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  priority_queue<P> q;
  for (int i = 0; i < n; i++) {
    q.push(P(-a[i], i));
    if (i < l - 1)
      continue;
    while (q.top().second <= i - l)
      q.pop();
    cout << -q.top().first;
    if (i == n - 1)
      cout << endl;
    else
      cout << " ";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, l, a[111111];
  cin >> n >> l;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  priority_queue<P> q;
  for (int i = 0; i < n; i++) {
    q.push(P(-a[i], i));
    if (i < l - 1)
      continue;
    while (q.top().second <= i - l)
      q.pop();
    cout << -q.top().first;
    if (i == n - 1)
      cout << endl;
    else
      cout << " ";
  }
  return 0;
}
Problem p02357 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int a[1000000];
int main() {
  int n, l;
  scanf("%d%d", &n, &l);
  rep(i, n) scanf("%d", &a[i]);
  multiset<int> se;
  rep(i, l) se.insert(a[i]);
  printf("%d", *se.begin());
  for (int i = l; i < n; i++) {
    se.insert(a[i]);
    se.erase(se.find(a[i - l]));
    printf(" %d", *se.begin());
  }
  puts("");
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int a[400000];
int main() {
  int n, l;
  scanf("%d%d", &n, &l);
  rep(i, n) scanf("%d", &a[i]);
  multiset<int> se;
  rep(i, l) se.insert(a[i]);
  printf("%d", *se.begin());
  for (int i = l; i < n; i++) {
    se.insert(a[i]);
    se.erase(se.find(a[i - l]));
    printf(" %d", *se.begin());
  }
  puts("");
}
Problem p02357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
#include <vector>

class data {
public:
  int arrnum;
  int num;
  data(int arrnum, int num) {
    this->arrnum = arrnum;
    this->num = num;
  };
};

bool operator>(const data &data1, const data &data2) {
  return data1.num > data2.num;
};

int main(int argc, char **argv) {
  int N, L, i, j;
  int min_arrnum = 0;
  int min_num = 0;

  std::cin >> N >> L;

  int *vec;
  vec = new int[N];

  for (i = 0; i < N; i++) {
    std::cin >> vec[i];
  }

  std::priority_queue<data, std::vector<data>, std::greater<data>> que;

  for (i = 0; i < N; i++) {
    que.push(data(i, vec[i]));
    if (i < L - 1)
      continue;
    while (que.top().arrnum <= i - L)
      que.pop();
    std::cout << que.top().num;
    if (i == N - 1)
      std::cout << std::endl;
    else
      std::cout << " ";
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <vector>

class data {
public:
  int arrnum;
  int num;
  data(int arrnum, int num) {
    this->arrnum = arrnum;
    this->num = num;
  };
};

bool operator>(const data &data1, const data &data2) {
  return data1.num > data2.num;
};

int main(int argc, char **argv) {
  int N, L, i, j;
  int min_arrnum = 0;
  int min_num = 0;

  std::cin >> N >> L;

  int *vec;
  vec = new int[N];

  for (i = 0; i < N; i++) {
    std::cin >> vec[i];
  }

  for (i = 0; i < N - (L - 1); i++) {
    if (min_arrnum < i || i == 0) {
      // std::priority_queue< int, std::vector<int>, std::greater<int> > que;
      std::priority_queue<data, std::vector<data>, std::greater<data>> que;
      for (j = i; j < i + L; j++) {
        // que.push(vec[j]);
        que.push(data(j, vec[j]));
      }
      min_arrnum = que.top().arrnum;
      min_num = que.top().num;

      // ss << que.top().num << " ";
      std::cout << min_num;
      if (i != N - L)
        std::cout << " ";
    }

    else {
      if (vec[i + L - 1] <= min_num) {
        min_num = vec[i + L - 1];
        min_arrnum = i + L - 1;
        std::cout << min_num;
        if (i != N - L)
          std::cout << " ";
      }

      else {
        std::cout << min_num;
        if (i != N - L)
          std::cout << " ";
      }
    }
  }

  std::cout << std::endl;

  return 0;
}
Problem p02358 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

struct rect {
  i64 x1, y1, x2, y2;
};

int main() {
  // assert(freopen("/Users/xuzijian/aoj/input", "r", stdin));
  int n;
  cin >> n;
  vector<rect> rs;
  map<i64, int> xs, ys;
  for (int i = 0; i < n; i++) {
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    xs[a];
    ys[b];
    xs[c];
    ys[d];
    rs.push_back({a, b, c, d});
  }
  int z = 0;
  map<int, i64> Xs, Ys;
  for (auto &p : xs) {
    p.second = z;
    Xs[z++] = p.first;
  }
  z = 0;
  for (auto &p : ys) {
    p.second = z;
    Ys[z++] = p.first;
  }

  vector<rect> cs;
  for (rect r : rs) {
    cs.push_back({xs[r.x1], ys[r.y1], xs[r.x2], ys[r.y2]});
  }

  vvi imos(4040, vi(4040));
  for (rect c : cs) {
    imos[c.x1][c.y1] += 1;
    imos[c.x1][c.y2] -= 1;
    imos[c.x2][c.y1] -= 1;
    imos[c.x2][c.y2] += 1;
  }

  for (int i = 0; i < 4040; i++) {
    for (int j = 0; j < 4040 - 1; j++) {
      imos[i][j + 1] += imos[i][j];
    }
  }
  for (int i = 0; i < 4040 - 1; i++) {
    for (int j = 0; j < 4040; j++) {
      imos[i + 1][j] += imos[i][j];
    }
  }

  i64 ans = 0;
  for (int i = 1; i < xs.size(); i++) {
    for (int j = 1; j < ys.size(); j++) {
      if (imos[i - 1][j - 1]) {
        ans += (Xs[i] - Xs[i - 1]) * (Ys[j] - Ys[j - 1]);
      }
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

struct rect {
  i64 x1, y1, x2, y2;
};

int main() {
  int n;
  cin >> n;
  vector<rect> rs;
  map<i64, int> xs, ys;
  for (int i = 0; i < n; i++) {
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    xs[a];
    ys[b];
    xs[c];
    ys[d];
    rs.push_back({a, b, c, d});
  }
  int z = 0;
  map<int, i64> Xs, Ys;
  for (auto &p : xs) {
    p.second = z;
    Xs[z++] = p.first;
  }
  z = 0;
  for (auto &p : ys) {
    p.second = z;
    Ys[z++] = p.first;
  }

  vector<rect> cs;
  for (rect r : rs) {
    cs.push_back({xs[r.x1], ys[r.y1], xs[r.x2], ys[r.y2]});
  }

  vvi imos(2020, vi(2020));
  for (rect c : cs) {
    imos[c.x1][c.y1] += 1;
    imos[c.x1][c.y2] -= 1;
    imos[c.x2][c.y1] -= 1;
    imos[c.x2][c.y2] += 1;
  }

  for (int i = 0; i < 2020; i++) {
    for (int j = 0; j < 2020 - 1; j++) {
      imos[i][j + 1] += imos[i][j];
    }
  }
  for (int i = 0; i < 2020 - 1; i++) {
    for (int j = 0; j < 2020; j++) {
      imos[i + 1][j] += imos[i][j];
    }
  }

  i64 ans = 0;
  for (int i = 1; i < xs.size(); i++) {
    for (int j = 1; j < ys.size(); j++) {
      if (imos[i - 1][j - 1]) {
        ans += (Xs[i] - Xs[i - 1]) * (Ys[j] - Ys[j - 1]);
      }
    }
  }
  cout << ans << endl;
}
Problem p02358 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
//
int n;
ll px[2000], py[2000], qx[2000], qy[2000];
int dp[8000][8000];
vector<ll> compress(ll *x1, ll *x2) {
  vector<ll> xs;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 1; j++) {
      xs.push_back(x1[i] + j);
      xs.push_back(x2[i] + j);
    }
  }
  xs.push_back(1e18 + 7);
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < n; i++) {
    x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
    x2[i] = lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin();
  };
  return xs;
}
//
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> px[i] >> py[i] >> qx[i] >> qy[i];
  }
  vector<ll> X = compress(px, qx);
  vector<ll> Y = compress(py, qy);
  for (int i = 0; i < n; i++) {
    dp[px[i]][py[i]]++;
    dp[qx[i]][qy[i]]++;
    dp[px[i]][qy[i]]--;
    dp[qx[i]][py[i]]--;
  }
  for (int i = 0; i < X.size() - 1; i++) {
    for (int j = 1; j < Y.size() - 1; j++) {
      dp[i][j] += dp[i][j - 1];
    }
  }
  for (int i = 0; i < Y.size() - 1; i++) {
    for (int j = 1; j < X.size() - 1; j++) {
      dp[j][i] += dp[j - 1][i];
    }
  }
  ll ans = 0;
  for (int i = 0; i < X.size() - 1; i++) {
    for (int j = 0; j < Y.size() - 1; j++) {
      if (dp[i][j] > 0) {
        ans += (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);
      }
    }
  }
  cout << ans << endl;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
//
int n;
ll px[2000], py[2000], qx[2000], qy[2000];
int dp[8000][8000];
vector<ll> compress(ll *x1, ll *x2) {
  vector<ll> xs;
  for (int i = 0; i < n; i++) {
    for (int j = -1; j <= 1; j++) {
      xs.push_back(x1[i] + j);
      xs.push_back(x2[i] + j);
    }
  }
  xs.push_back(1e18 + 7);
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < n; i++) {
    x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
    x2[i] = lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin();
  };
  return xs;
}
//
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> px[i] >> py[i] >> qx[i] >> qy[i];
  }
  vector<ll> X = compress(px, qx);
  vector<ll> Y = compress(py, qy);
  for (int i = 0; i < n; i++) {
    dp[px[i]][py[i]]++;
    dp[qx[i]][qy[i]]++;
    dp[px[i]][qy[i]]--;
    dp[qx[i]][py[i]]--;
  }
  for (int i = 0; i < X.size() - 1; i++) {
    for (int j = 1; j < Y.size() - 1; j++) {
      dp[i][j] += dp[i][j - 1];
    }
  }
  for (int i = 0; i < Y.size() - 1; i++) {
    for (int j = 1; j < X.size() - 1; j++) {
      dp[j][i] += dp[j - 1][i];
    }
  }
  ll ans = 0;
  for (int i = 0; i < X.size() - 1; i++) {
    for (int j = 0; j < Y.size() - 1; j++) {
      if (dp[i][j] > 0) {
        ans += (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);
      }
    }
  }
  cout << ans << endl;
}
Problem p02358 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n;
int X1[2000], Y1[2000], X2[2000], Y2[2000];
int fld[4000][4000];
int compress(int *X1, int *X2, vector<int> &X) {
  rep(i, n) {
    X.push_back(X1[i]);
    X.push_back(X2[i]);
  }
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  rep(i, n) {
    X1[i] = lower_bound(X.begin(), X.end(), X1[i]) - X.begin();
    X2[i] = lower_bound(X.begin(), X.end(), X2[i]) - X.begin();
  }
  return X.size();
}
int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
  vector<int> a, b;
  int w = compress(X1, X2, a), h = compress(Y1, Y2, b);
  rep(i, n) {
    for (int j = X1[i]; j < X2[i]; j++)
      for (int k = Y1[i]; k < Y2[i]; k++)
        fld[j][k] = true;
  }
  ll ans = 0;
  rep(i, w - 1) rep(j, h - 1) {
    if (fld[i][j])
      ans += ((ll)a[i + 1] - a[i]) * (b[j + 1] - b[j]);
  }
  printf("%lld\\n", ans);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n;
int X1[2000], Y1[2000], X2[2000], Y2[2000];
int fld[2000][2000];
int compress(int *X1, int *X2, vector<int> &X) {
  rep(i, n) {
    X.push_back(X1[i]);
    X.push_back(X2[i]);
  }
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  rep(i, n) {
    X1[i] = lower_bound(X.begin(), X.end(), X1[i]) - X.begin();
    X2[i] = lower_bound(X.begin(), X.end(), X2[i]) - X.begin();
  }
  return X.size();
}
int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
  vector<int> a, b;
  int w = compress(X1, X2, a), h = compress(Y1, Y2, b);
  rep(i, n) {
    for (int j = X1[i]; j < X2[i]; j++)
      for (int k = Y1[i]; k < Y2[i]; k++)
        fld[j][k] = true;
  }
  ll ans = 0;
  rep(i, w - 1) rep(j, h - 1) {
    if (fld[i][j])
      ans += ((ll)a[i + 1] - a[i]) * (b[j + 1] - b[j]);
  }
  printf("%lld\\n", ans);
}
Problem p02358 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 2005;

vector<int> X, Y, X1, Y1, X2, Y2;
bool flag[MAX_N * 2][MAX_N * 2];
int n;

int main() {
  int p, q, r, s;
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d%d%d%d", &p, &q, &r, &s);
    X.push_back(p), X.push_back(r);
    Y.push_back(q), Y.push_back(s);
    X1.push_back(p), X2.push_back(r);
    Y1.push_back(q), Y2.push_back(s);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  rep(i, n) {
    X1[i] = lower_bound(X.begin(), X.end(), X1[i]) - X.begin();
    Y1[i] = lower_bound(Y.begin(), Y.end(), Y1[i]) - Y.begin();
    X2[i] = lower_bound(X.begin(), X.end(), X2[i]) - X.begin();
    Y2[i] = lower_bound(Y.begin(), Y.end(), Y2[i]) - Y.begin();
  }
  rep(i, n) {
    for (int j = Y1[i]; j < Y2[i]; j++) {
      for (int k = X1[i]; k < X2[i]; k++) {
        flag[j][k] = true;
      }
    }
  }
  ll ans = 0;
  rep(i, Y.size() - 1) {
    rep(j, X.size() - 1) {
      if (flag[i][j]) {
        ans += (ll)(X[j + 1] - X[j]) * (Y[i + 1] - Y[i]);
      }
    }
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 2005;

vector<int> X, Y, X1, Y1, X2, Y2;
bool flag[MAX_N][MAX_N];
int n;

int main() {
  int p, q, r, s;
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d%d%d%d", &p, &q, &r, &s);
    X.push_back(p), X.push_back(r);
    Y.push_back(q), Y.push_back(s);
    X1.push_back(p), X2.push_back(r);
    Y1.push_back(q), Y2.push_back(s);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  rep(i, n) {
    X1[i] = lower_bound(X.begin(), X.end(), X1[i]) - X.begin();
    Y1[i] = lower_bound(Y.begin(), Y.end(), Y1[i]) - Y.begin();
    X2[i] = lower_bound(X.begin(), X.end(), X2[i]) - X.begin();
    Y2[i] = lower_bound(Y.begin(), Y.end(), Y2[i]) - Y.begin();
  }
  rep(i, n) {
    for (int j = Y1[i]; j < Y2[i]; j++) {
      for (int k = X1[i]; k < X2[i]; k++) {
        flag[j][k] = true;
      }
    }
  }
  ll ans = 0;
  rep(i, Y.size() - 1) {
    rep(j, X.size() - 1) {
      if (flag[i][j]) {
        ans += (ll)(X[j + 1] - X[j]) * (Y[i + 1] - Y[i]);
      }
    }
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02358 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)

ll N;
vector<ll> x, y;
ll x1[2000], y1[2000], x2[2000], y2[2000];

ll c[4020][4020]; // x1,x2があるのでNの倍必要

int main() {
  cin >> N;
  rep(i, N) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i]; //[x1,x2) [y1,y2)

    x.push_back(x1[i]);
    x.push_back(x2[i]);
    y.push_back(y1[i]);
    y.push_back(y2[i]);
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());

  rep(i, N) {
    ll ix1 = lower_bound(x.begin(), x.end(), x1[i]) - x.begin();
    ll ix2 = lower_bound(x.begin(), x.end(), x2[i]) - x.begin();
    ll iy1 = lower_bound(y.begin(), y.end(), y1[i]) - y.begin();
    ll iy2 = lower_bound(y.begin(), y.end(), y2[i]) - y.begin();

    c[iy1][ix1]++;
    c[iy1][ix2]--;
    c[iy2][ix1]--;
    c[iy2][ix2]++;
  }

  rep(i, y.size()) {
    rep(j, x.size() - 1) { c[i][j + 1] += c[i][j]; }
  }

  rep(j, x.size()) {
    rep(i, y.size() - 1) { c[i + 1][j] += c[i][j]; }
  }

  ll ans = 0;
  rep(i, y.size() - 1) {
    rep(j, x.size() - 1) {
      if (c[i][j] > 0) {
        ans += (x[j + 1] - x[j]) * (y[i + 1] - y[i]);
      }
    }
  }

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


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)

ll N;
vector<ll> x, y;
ll x1[2000], y1[2000], x2[2000], y2[2000];

ll c[2020][2020];

int main() {
  cin >> N;
  rep(i, N) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i]; //[x1,x2) [y1,y2)

    x.push_back(x1[i]);
    x.push_back(x2[i]);
    y.push_back(y1[i]);
    y.push_back(y2[i]);
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());

  rep(i, N) {
    ll ix1 = lower_bound(x.begin(), x.end(), x1[i]) - x.begin();
    ll ix2 = lower_bound(x.begin(), x.end(), x2[i]) - x.begin();
    ll iy1 = lower_bound(y.begin(), y.end(), y1[i]) - y.begin();
    ll iy2 = lower_bound(y.begin(), y.end(), y2[i]) - y.begin();

    c[iy1][ix1]++;
    c[iy1][ix2]--;
    c[iy2][ix1]--;
    c[iy2][ix2]++;
  }

  rep(i, y.size()) {
    rep(j, x.size() - 1) { c[i][j + 1] += c[i][j]; }
  }

  rep(j, x.size()) {
    rep(i, y.size() - 1) { c[i + 1][j] += c[i][j]; }
  }

  ll ans = 0;
  rep(i, y.size() - 1) {
    rep(j, x.size() - 1) {
      if (c[i][j] > 0) {
        ans += (x[j + 1] - x[j]) * (y[i + 1] - y[i]);
      }
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02358 (C++) — buggy submission, verdict: Runtime Error

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

int compress(vector<int> &xs, map<int, int> &x) {
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < xs.size(); i++) {
    x[xs[i]] = i;
  }
  return xs.size();
}

int main() {
  int n;
  int x1[2000], x2[2000], y1[2000], y2[2000];
  static int field[4000][4000];
  vector<int> xs, ys;
  map<int, int> x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d %d", x1 + i, y1 + i, x2 + i, y2 + i);
    xs.push_back(x1[i]);
    xs.push_back(x2[i]);
    ys.push_back(y1[i]);
    ys.push_back(y2[i]);
  }
  int w = compress(xs, x);
  int h = compress(ys, y);
  fill(field[0], field[0] + 4000000, 0);
  for (int i = 0; i < n; i++) {
    int xx1 = x[x1[i]], xx2 = x[x2[i]], yy1 = y[y1[i]], yy2 = y[y2[i]];
    field[xx1][yy1]++;
    field[xx2][yy2]++;
    field[xx1][yy2]--;
    field[xx2][yy1]--;
  }
  for (int i = 1; i < w; i++)
    for (int j = 0; j < h; j++)
      field[i][j] += field[i - 1][j];
  for (int i = 1; i < h; i++)
    for (int j = 0; j < w; j++)
      field[j][i] += field[j][i - 1];
  long long ans = 0;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      long long dx = xs[i + 1] - xs[i], dy = ys[j + 1] - ys[j];
      if (field[i][j] > 0)
        ans += dx * dy;
    }
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

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

int compress(vector<int> &xs, map<int, int> &x) {
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < xs.size(); i++) {
    x[xs[i]] = i;
  }
  return xs.size();
}

int main() {
  int n;
  int x1[2000], x2[2000], y1[2000], y2[2000];
  vector<int> xs, ys;
  map<int, int> x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d %d", x1 + i, y1 + i, x2 + i, y2 + i);
    xs.push_back(x1[i]);
    xs.push_back(x2[i]);
    ys.push_back(y1[i]);
    ys.push_back(y2[i]);
  }
  int w = compress(xs, x);
  int h = compress(ys, y);
  int field[w][h];
  fill(field[0], field[0] + w * h, 0);
  for (int i = 0; i < n; i++) {
    int xx1 = x[x1[i]], xx2 = x[x2[i]], yy1 = y[y1[i]], yy2 = y[y2[i]];
    field[xx1][yy1]++;
    field[xx2][yy2]++;
    field[xx1][yy2]--;
    field[xx2][yy1]--;
  }
  for (int i = 1; i < w; i++)
    for (int j = 0; j < h; j++)
      field[i][j] += field[i - 1][j];
  for (int i = 1; i < h; i++)
    for (int j = 0; j < w; j++)
      field[j][i] += field[j][i - 1];
  long long ans = 0;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      long long dx = xs[i + 1] - xs[i], dy = ys[j + 1] - ys[j];
      if (field[i][j] > 0)
        ans += dx * dy;
    }
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02358 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int64;

int main() {
  int N, XX[2000][4];

  cin >> N;
  vector<int> nums;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> XX[i][j];
      nums.push_back(XX[i][j]);
    }
  }

  sort(begin(nums), end(nums));
  nums.erase(unique(begin(nums), end(nums)), end(nums));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      XX[i][j] = lower_bound(begin(nums), end(nums), XX[i][j]) - begin(nums);
    }
  }

  vector<vector<int>> sum(nums.size(), vector<int>(nums.size(), 0));
  for (int i = 0; i < N; i++) {
    ++sum[XX[i][0]][XX[i][1]];
    --sum[XX[i][2]][XX[i][1]];
    --sum[XX[i][0]][XX[i][3]];
    ++sum[XX[i][2]][XX[i][3]];
  }

  for (int i = 1; i < nums.size(); i++) {
    for (int j = 0; j < nums.size(); j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  for (int i = 0; i < nums.size(); i++) {
    for (int j = 1; j < nums.size(); j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }

  int64 ret = 0;
  for (int i = 0; i + 1 < nums.size(); i++) {
    for (int j = 0; j + 1 < nums.size(); j++) {
      if (sum[i][j] > 0) {
        ret += 1LL * (nums[i + 1] - nums[i]) * (nums[j + 1] - nums[j]);
      }
    }
  }

  cout << ret << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int64;

int main() {
  int N, XX[4][2000];

  cin >> N;
  vector<int> nums;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> XX[i][j];
      // if(j >= 2) ++XX[i][j];
      nums.push_back(XX[i][j]);
    }
  }

  sort(begin(nums), end(nums));
  nums.erase(unique(begin(nums), end(nums)), end(nums));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      XX[i][j] = lower_bound(begin(nums), end(nums), XX[i][j]) - begin(nums);
    }
  }

  vector<vector<int>> sum(nums.size(), vector<int>(nums.size(), 0));
  for (int i = 0; i < N; i++) {
    ++sum[XX[i][0]][XX[i][1]];
    --sum[XX[i][2]][XX[i][1]];
    --sum[XX[i][0]][XX[i][3]];
    ++sum[XX[i][2]][XX[i][3]];
  }

  for (int i = 1; i < nums.size(); i++) {
    for (int j = 0; j < nums.size(); j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  for (int i = 0; i < nums.size(); i++) {
    for (int j = 1; j < nums.size(); j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }

  int64 ret = 0;
  for (int i = 0; i + 1 < nums.size(); i++) {
    for (int j = 0; j + 1 < nums.size(); j++) {
      if (sum[i][j] > 0) {
        ret += 1LL * (nums[i + 1] - nums[i]) * (nums[j + 1] - nums[j]);
      }
    }
  }

  cout << ret << endl;
}