alexjercan/bugnet huggingface dataset:
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

int INF = 10e8;
const int max_n = 10e5;
int x[max_n + 1];
int y[max_n + 1];
int w[max_n + 1];

int wseg[2 * max_n + 1];
int hseg[2 * max_n + 1];

int pow2(int n_) {
  int n = 1;
  while (n < n_)
    n *= 2;
  return n;
}

void init(int n_, int seg[]) {
  int n = pow2(n_);
  REP(i, 2 * n - 1) seg[i] = 1;
  REP(i, (2 * n - 1) - (n - n_)) seg[i] = 0;
}

void query(int a, int b, int k, int l, int r, int seg[]) {
  if (r <= a || b <= l)
    return;
  if (a <= l && r <= b) {
    seg[k] = 1;
    return;
  } else {
    query(a, b, k * 2 + 1, l, (l + r) / 2, seg);
    query(a, b, k * 2 + 2, (l + r) / 2, r, seg);
  }
}

int update(int n_, int seg[]) {
  int n = pow2(n_);
  REP(i, n) {
    int k = i + n - 1;
    while (k > 0) {
      k = (k - 1) / 2;
      seg[k] = max(seg[k], min(seg[k * 2 + 1], seg[k * 2 + 2]));
    }
  }
  return seg[0];
}

int main() {
  int n, W, H;
  cin >> n >> W >> H;

  REP(i, n) { cin >> x[i] >> y[i] >> w[i]; }

  init(2 * W + 1, wseg);
  init(2 * H + 1, hseg);

  REP(i, n) {
    query(max(0, 2 * (x[i] - w[i])), min(2 * W + 1, 2 * (x[i] + w[i]) + 1), 0,
          0, pow2(2 * W + 1), wseg);
    query(max(0, 2 * (y[i] - w[i])), min(2 * W + 1, 2 * (y[i] + w[i]) + 1), 0,
          0, pow2(2 * H + 1), hseg);
  }

  /*
  REP(i, 2*pow2(2*W+1)-1) cout << wseg[i];
  cout << endl;
  REP(i, 2*pow2(2*H+1)-1) cout << hseg[i];
  cout << endl;
  */
  if (update(2 * W + 1, wseg) || update(2 * H + 1, hseg)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

int INF = 10e8;
const int max_n = 10e5;
int wlist[2 * max_n + 1];
int hlist[2 * max_n + 1];
int x[max_n + 1];
int y[max_n + 1];
int w[max_n + 1];

int main() {
  int n, W, H;
  cin >> n >> W >> H;

  REP(i, n) { cin >> x[i] >> y[i] >> w[i]; }

  fill(wlist, wlist + (2 * W + 1), 0);
  fill(hlist, hlist + (2 * H + 1), 0);

  REP(i, n) {
    fill(wlist + max(0, 2 * (x[i] - w[i])),
         wlist + min(2 * W + 1, 2 * (x[i] + w[i]) + 1), 1);
    fill(hlist + max(0, 2 * (y[i] - w[i])),
         hlist + min(2 * H + 1, 2 * (y[i] + w[i]) + 1), 1);
  }

  bool wflag = true;
  bool hflag = true;
  REP(i, 2 * W + 1) {
    if (wlist[i] == 0)
      wflag = false;
  }
  REP(i, 2 * H + 1) {
    if (hlist[i] == 0)
      hflag = false;
  }

  if (wflag || hflag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int n, w, h;

int limit(int p, int llimit, int hlimit) {
  if (p < llimit)
    return llimit;
  if (p > hlimit)
    return hlimit;
  return p;
}

bool isCovered(vector<int> *x, vector<int> *y) {
  bool b = true;
  for (int i = 0; i < w; i++) {
    b &= (x->at(i) > 0);
  }
  for (int j = 0; j < h; j++) {
    if (b == false && y->at(j) <= 0)
      return false;
  }
  return true;
}

int main(void) {

  string s[] = {"No", "Yes"};
  cin >> n >> w >> h;
  vector<int> xlist(w + 1, 0);
  vector<int> ylist(h + 1, 0);

  for (int i = 0; i < n; i++) {
    int x_i, y_i, w_i;
    cin >> x_i >> y_i >> w_i;
    xlist[limit(x_i - w_i, 0, w)]++;
    xlist[limit(x_i + w_i, 0, w)]--;
    ylist[limit(y_i - w_i, 0, h)]++;
    ylist[limit(y_i + w_i, 0, h)]--;
  }

  for (int i = 1; i <= w; i++)
    xlist[i] += xlist[i - 1];
  for (int i = 1; i <= h; i++)
    ylist[i] += ylist[i - 1];

  cout << s[isCovered(&xlist, &ylist)] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int n, w, h;

int limit(int p, int llimit, int hlimit) {
  if (p < llimit)
    return llimit;
  if (p > hlimit)
    return hlimit;
  return p;
}

bool isCovered(vector<int> *x, vector<int> *y) {
  bool b = true;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      b &= (x->at(i) > 0 || y->at(j) > 0);
    }
  }
  return b;
}

int main(void) {

  string s[] = {"No", "Yes"};
  cin >> n >> w >> h;
  vector<int> xlist(w + 1, 0);
  vector<int> ylist(h + 1, 0);

  for (int i = 0; i < n; i++) {
    int x_i, y_i, w_i;
    cin >> x_i >> y_i >> w_i;
    xlist[limit(x_i - w_i, 0, w)]++;
    xlist[limit(x_i + w_i, 0, w)]--;
    ylist[limit(y_i - w_i, 0, h)]++;
    ylist[limit(y_i + w_i, 0, h)]--;
  }

  for (int i = 1; i <= w; i++)
    xlist[i] += xlist[i - 1];
  for (int i = 1; i <= h; i++)
    ylist[i] += ylist[i - 1];

  cout << s[isCovered(&xlist, &ylist)] << endl;

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

#include <algorithm>
#include <iostream>

using namespace std;

int xdp[216000], ydp[216000];
int n, W, H;
int x, y, w;
int main() {
  cin >> n >> W >> H;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> w;
    xdp[max(x - w, 0)]++;
    xdp[x + w]--;
    ydp[max(y - w, 0)]++;
    ydp[y + w]--;
  }
  int ok = 2;
  for (int i = 0; i < W; i++) {
    if (i)
      xdp[i] += xdp[i - 1];
    if (xdp[i] == 0) {
      ok--;
      break;
    }
  }

  for (int i = 0; i < H; i++) {
    if (i)
      ydp[i] += ydp[i - 1];
    if (ydp[i] == 0) {
      ok--;
      break;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int xdp[108000], ydp[108000];
int n, W, H;
int x, y, w;
int main() {
  cin >> n >> W >> H;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> w;
    xdp[max(x - w, 0)]++;
    xdp[x + w]--;
    ydp[max(y - w, 0)]++;
    ydp[y + w]--;
  }
  int ok = 2;
  for (int i = 0; i < W; i++) {
    if (i)
      xdp[i] += xdp[i - 1];
    if (xdp[i] == 0) {
      ok--;
      break;
    }
  }

  for (int i = 0; i < H; i++) {
    if (i)
      ydp[i] += ydp[i - 1];
    if (ydp[i] == 0) {
      ok--;
      break;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  vector<int> row_vector(w + 1, 0), col_vector(h + 1, 0);
  for (int i = 0; i < n; ++i) {
    int p_w, p_h, r;
    cin >> p_w >> p_h >> r;
    int left, right;
    left = max(p_w - r, 0), right = min(p_w + r, w);
    row_vector[left]++;
    row_vector[right]--;
    left = max(p_h - r, 0), right = min(p_h + r, h);
    col_vector[left]++;
    col_vector[right]--;
  }
  int row_flag = 1, col_flag = 1;
  int sum;
  sum = 0;
  for (int i = 0; i < w; ++i) {
    sum += row_vector[i];
    row_vector[i] = sum;
    if (sum <= 0) {
      row_flag = 0;
      break;
    }
  }
  sum = 0;
  for (int i = 0; i < h; ++i) {
    sum += col_vector[i];
    col_vector[i] = sum;
    if (sum <= 0) {
      col_flag = 0;
      break;
    }
  }
  cout << ((row_flag + col_flag) ? "Yes" : "No") << endl;
  return 0;
}

// [Problem] Koto Distance
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2600&lang=jp
//
// imos法
// 区間の重複の数を高速に調べるためのアルゴリズム
// [0, 3]と[2, 5]が与えられたときに,
// [0, 2)は重複1, [2, 3]は重複2, (3, 5]は重複1, それ以外は0
// と答えたいというような問題に使える.
// 簡単の為に各区間が[l, r)の形であるものだけを考えよう.
// 一見そうでなくてもこの形で表現する方法はあるものはたくさん.
//
// 位置lの得点を1だけ増やし（＋１し), 位置rの得点を1だけ減らす(-1する).
// この処理を各区間に対して行っておき, 最後に左から順に累積和を取っていけば良い
// そうすると区間に入ると+1, 出ると-1になるから,
// 累積和として今「入っている」区間の総数が得られる.
// これはまさに区間の重複の数に他ならない.
//
// 本問題では, 行・列それぞれについて芋すほうを適用してみよう
// (行・列を別々に考えるところまではわかったんだけど...)


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <unordered_set>

using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  unordered_set<int> width_set, height_set;
  for (int i = 0; i < n; i++) {
    int p_w, p_h, p_r;
    cin >> p_w >> p_h >> p_r;
    for (int q_w = max(p_w - p_r, 0); q_w < min(p_w + p_r, w); q_w++) {
      width_set.emplace(q_w);
    }
    for (int q_h = max(p_h - p_r, 0); q_h < min(p_h + p_r, h); q_h++) {
      height_set.emplace(q_h);
    }
  }
  cout << ((width_set.size() == w || height_set.size() == h) ? "Yes" : "No")
       << endl;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

int x[200000], y[200000];

int main(void) {
  int n, w, h;
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 0; i < n; i++) {
    int xi, yi, wi;
    scanf("%d%d%d", &xi, &yi, &wi);
    x[MAX(0, xi - wi)]++;
    x[MIN(xi + wi, w)]--;
    y[MAX(0, yi - wi)]++;
    y[MIN(yi + wi, h)]--;
  }
  bool flag = true;
  for (int i = 0; i < w; i++) {
    x[i + 1] += x[i];
    if (x[i] <= 0)
      flag = false;
  }
  bool flag2 = true;
  for (int i = 0; i < h; i++) {
    y[i + 1] += y[i];
    if (y[i] <= 0)
      flag2 = false;
  }
  printf((flag || flag2) ? "Yes\\n" : "No\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

int x[20000], y[20000];

int main(void) {
  int n, w, h;
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 0; i < n; i++) {
    int xi, yi, wi;
    scanf("%d%d%d", &xi, &yi, &wi);
    x[MAX(0, xi - wi)]++;
    x[MIN(xi + wi, w) + 1]--;
    y[MAX(0, yi - wi)]++;
    y[MIN(yi + wi, h) + 1]--;
  }
  bool flag = true;
  for (int i = 0; i <= w; i++) {
    x[i + 1] += x[i];
    if (x[i] <= 0)
      flag = false;
  }
  bool flag2 = true;
  for (int i = 0; i <= h; i++) {
    y[i + 1] += y[i];
    if (y[i] <= 0)
      flag2 = false;
  }
  printf((flag || flag2) ? "Yes\\n" : "No\\n");
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;

int x[200000], y[200000], n, w, h, x_1, y_1, w1, ok = true;
int main() {
  cin >> n >> w >> h;
  for (int i = 0; i < n; i++) {
    cin >> x_1 >> y_1 >> w1;
    x[max(0, x_1 - w1)]++;
    y[max(0, y_1 - w1)]++;
    x[min(w, x_1 + w1)]--;
    y[min(h, y_1 + w1)]--;
  }
  for (int i = 1; i < w; i++) {
    x[i] += x[i - 1];
  }
  for (int i = 1; i < h; i++) {
    y[i] += y[i - 1];
  }
  for (int i = 0; i < w; i++) {
    if (x[i] == 0) {
      ok = false;
    }
  }
  for (int i = 0; i < h; i++) {
    if (y[i] == 0 && ok == false) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int h[1000000], w[1000000], H, W, N, i, A, B, C;
int main() {
  cin >> N >> H >> W;
  N = min(N, 50000);
  for (int j = 0; j < N; j++) {
    cin >> A >> B >> C;
    if (C == min(H, W)) {
      goto E2;
    }
    for (i = max(0, A - C); i < min(H, A + C); i++) {
      h[i] = true;
    }
    for (i = max(0, B - C); i < min(W, B + C); i++) {
      w[i] = true;
    }
  }
  for (int i = 0; i < H; i++) {
    if (h[i] == false) {
      goto E1;
    }
  }
  goto E2;
E1:;
  for (int i = 0; i < W; i++) {
    if (w[i] == false) {
      goto E3;
    }
  }
E2:;
  cout << "Yes" << endl;
  goto E4;
E3:;
  cout << "No" << endl;
E4:;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000
using namespace std;
typedef pair<int, int> P;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int N, W, H;
  cin >> N >> W >> H;
  vector<int> h(H + 10, 0);
  vector<int> w(W + 10, 0);
  rep(i, N) {
    int x, y, p;
    // cin >> x >> y >> p;
    scanf("%d%d%d", &x, &y, &p);
    h[max(0, y - p)]++;
    h[min(y + p, H + 1)]--;
    w[max(0, x - p)]++;
    w[min(x + p, W + 1)]--;
  }
  for (int i = 0; i <= W; i++) {
    if (i == 0)
      continue;
    w[i] += w[i - 1];
  }
  for (int i = 0; i <= H; i++) {
    if (i == 0)
      continue;
    h[i] += h[i - 1];
  }
  bool flag = false;
  for (int i = 0; i < W; i++) {
    if (w[i] == 0)
      // 0があったらもう片方を確認する
      flag = true;
  }
  if (flag == false) {
    cout << "Yes" << endl;
    return 0;
  } else {
    for (int i = 0; i < H; i++) {
      if (h[i] == 0)
        flag = false;
    }
  }
  if (!flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  // return 0;
  /*rep(i, W + 1) cout << w[i] << " ";
  cout << endl;
  rep(i, H + 1) cout << h[i] << " ";
  cout << endl;*/
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000
using namespace std;
typedef pair<int, int> P;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int N, W, H;
  cin >> N >> W >> H;
  vector<int> h(20000, 0);
  vector<int> w(20000, 0);
  rep(i, N) {
    int x, y, p;
    // cin >> x >> y >> p;
    scanf("%d%d%d", &x, &y, &p);
    int y_first = y - p;
    int y_last = y + p + 1;
    h[max(0, y_first)]++;
    h[min(y_last, H + 1)]--;
    int x_first = x - p;
    int x_last = x + p + 1;
    w[max(0, x_first)]++;
    w[min(x_last, W + 1)]--;
  }
  for (int i = 0; i <= W; i++) {
    if (i == 0)
      continue;
    w[i] += w[i - 1];
  }
  for (int i = 0; i <= H; i++) {
    if (i == 0)
      continue;
    h[i] += h[i - 1];
  }
  bool flag = false;

  for (int i = 0; i <= W; i++) {
    if (w[i] == 0)
      // 0があったらもう片方を確認する
      flag = true;
  }
  if (flag == false) {
    cout << "Yes" << endl;
    return 0;
  } else {
    for (int i = 0; i <= H; i++) {
      if (h[i] == 0)
        flag = false;
    }
  }
  if (!flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
  /*rep(i, W + 1) cout << w[i] << " ";
  cout << endl;
  rep(i, H + 1) cout << h[i] << " ";
  cout << endl;*/
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  vector<int> pw(w + 1e6);
  vector<int> mw(w + 1e6);
  vector<int> ph(h + 1e6);
  vector<int> mh(h + 1e6);

  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    int mx = x - z;
    if (mx < 0)
      mx = 0;
    pw[mx]++;
    mw[x + z + 1]--;

    int my = y - z;
    if (my < 0)
      my = 0;
    ph[my]++;
    mh[y + z + 1]--;
  }

  int flag = 1;

  int tmp = pw[0];

  for (int i = 1; i <= w; i++) {
    tmp += mw[i];
    if (tmp == 0) {
      flag = 0;
      break;
    }
    tmp += pw[i];
  }

  if (flag == 1) {
    cout << "Yes" << endl;
    return 0;
  }

  flag = 1;

  tmp = ph[0];

  for (int i = 1; i <= h; i++) {
    tmp += mh[i];
    if (tmp == 0) {
      flag = 0;
      break;
    }
    tmp += ph[i];
  }

  if (flag == 1) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  vector<int> imow(w + 1e5 + 1, 0);
  vector<int> imoh(h + 1e5 + 1, 0);
  for (int i = 0; i < n; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    imow[x - r]++;
    imow[x + r + 1]--;
    imoh[y - r]++;
    imoh[y + r + 1]--;
  }

  int flag = 1;

  int iw = 0;
  for (int i = 0; i < w; i++) {
    iw += imow[i];
    if (iw == 0) {
      flag = 0;
    }
  }

  if (flag == 1) {
    cout << "Yes" << endl;
    return 0;
  }

  flag = 1;

  int ih = 0;
  for (int i = 0; i < h; i++) {
    ih += imoh[i];
    if (ih == 0) {
      flag = 0;
    }
  }

  if (flag == 1) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

class SegTree {
private:
  int size;

  vector<int> sumvalue;

  void _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) {
      return;
    }
    if (a <= l && r <= b) {
      sumvalue[k] = 1;
      return;
    }

    _query(a, b, 2 * k, l, (l + r) / 2);
    _query(a, b, 2 * k + 1, (l + r) / 2, r);
  }

public:
  SegTree(int size_) {
    for (size = 1; size < size_;) {
      size <<= 1;
    }

    sumvalue = vector<int>(size * 2, 0);
  }

  int value(int i) {
    i += size;

    while (i > 1) {
      if (sumvalue[i] == 1) {
        return 1;
      }

      i = i / 2;
    }

    return 0;
  }

  void query(int s, int t) { _query(s, t, 1, 0, size); }
};

int main() {
  int H, W, N, x, y, w;

  cin >> N >> W >> H;

  SegTree ok1(2 * H + 1); // Y - Axis
  SegTree ok2(2 * W + 1); // X - Axis

  for (int i = 0; i < N; i++) {
    cin >> x >> y >> w;

    ok1.query(max(2 * y - 2 * w, 0), min(2 * y + 2 * w, 2 * H) + 1);
    ok2.query(max(2 * x - 2 * w, 0), min(2 * x + 2 * w, 2 * W) + 1);
  }

  int ok3 = 2 * H + 1, ok4 = 2 * W + 1;

  for (int i = 0; i <= 2 * H; i++) {
    ok3 -= ok1.value(i);
  }

  for (int i = 0; i <= 2 * W; i++) {
    ok4 -= ok2.value(i);
  }

  cout << (ok3 && ok4 ? "No" : "Yes") << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int H, W, N, x, y, w;

  cin >> N >> W >> H;

  vector<int> ok1(2 * H + 1, 0); // Y - Axis
  vector<int> ok2(2 * W + 1, 0); // X - Axis

  for (int i = 0; i < N; i++) {
    cin >> x >> y >> w;

    for (int j = -(2 * w); j <= 2 * w; j++) {
      if (0 <= 2 * y + j && 2 * y + j <= 2 * H) {
        ok1[2 * y + j]++;
      }

      if (0 <= 2 * x + j && 2 * x + j <= 2 * W) {
        ok2[2 * x + j]++;
      }
    }
  }

  int ok3 = 2 * H + 1, ok4 = 2 * W + 1;

  for (int i = 0; i <= 2 * H; i++) {
    ok3 -= (ok1[i] == 0 ? 0 : 1);
  }

  for (int i = 0; i <= 2 * W; i++) {
    ok4 -= (ok2[i] == 0 ? 0 : 1);
  }

  cout << (ok3 && ok4 ? "No" : "Yes") << endl;

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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int N, W, H;
int x[100005];
int y[100005];

int main() {
  cin >> N >> W >> H;

  rep(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    x[max(0, a - c)]++;
    x[min(100005, a + c)]--;
    y[max(0, b - c)]++;
    y[min(100005, b + c)]--;
  }
  rep(i, W) x[i + 1] += x[i];
  rep(i, H) y[i + 1] += y[i];

  bool f1 = true, f2 = true;
  rep(i, W) f1 &= x[i] > 0;
  rep(i, H) f2 &= y[i] > 0;

  if (f1 || f2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int N, W, H;
int x[100005];
int y[100005];

int main() {
  cin >> N >> W >> H;

  rep(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    x[max(0, a - c)]++;
    x[a + c]--;
    y[max(0, b - c)]++;
    y[b + c]--;
  }
  rep(i, W) x[i + 1] += x[i];
  rep(i, H) y[i + 1] += y[i];

  bool f1 = true, f2 = true;
  rep(i, W) f1 &= x[i] > 0;
  rep(i, H) f2 &= y[i] > 0;

  if (f1 || f2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, w, h, ans = 0;
  pair<int, int> han[2][100001];
  cin >> n >> w >> h;
  for (int i = 0, x, y, z; i < n; i++) {
    cin >> x >> y >> z;
    han[0][i] = P(x - z, x + z);
    han[1][i] = P(y - z, y + z);
  }
  han[0][n] = P(w, w);
  han[1][n++] = P(h, h);
  for (int i = 0; i < 2; i++)
    sort(han[i], han[i] + n);
  for (int i = 0; i < 2; i++) {
    int mx = 0, f = 1;
    for (int j = 0; j < n; j++) {
      if (han[i][j].first > mx)
        f = 0;
      mx = max(mx, han[i][j].second);
    }
    if (f)
      ans = 1;
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, w, h, ans = 0;
  pair<int, int> han[2][10001];
  cin >> n >> w >> h;
  for (int i = 0, x, y, z; i < n; i++) {
    cin >> x >> y >> z;
    han[0][i] = P(x - z, x + z);
    han[1][i] = P(y - z, y + z);
  }
  han[0][n] = P(w, w);
  han[1][n++] = P(h, h);
  for (int i = 0; i < 2; i++)
    sort(han[i], han[i] + n);
  for (int i = 0; i < 2; i++) {
    int mx = 0, f = 1;
    for (int j = 0; j < n; j++) {
      if (han[i][j].first > mx)
        f = 0;
      mx = max(mx, han[i][j].second);
    }
    if (f)
      ans = 1;
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int X[100005], Y[100005];

int main() {
  int n, W, H;
  cin >> n >> W >> H;

  memset(X, 0, sizeof(X));
  memset(Y, 0, sizeof(Y));

  rep(i, n) {
    int x, y, w;
    cin >> x >> y >> w;

    X[max(0, x - w)]++;
    X[min(W, x + w)]--;

    Y[max(0, y - w)]++;
    Y[min(H, y + w)]--;
  }

  REP(i, 1, 100005) {
    X[i] += X[i - 1];
    Y[i] += Y[i - 1];
  }

  bool a = true, b = true;
  REP(i, 0, W) {
    if (X[i] == 0)
      a = false;
  }

  REP(i, 0, H) {
    if (Y[i] == 0)
      b = false;
  }

  if (a || b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int X[10005], Y[100005];

int main() {
  int n, W, H;
  cin >> n >> W >> H;

  memset(X, 0, sizeof(X));
  memset(Y, 0, sizeof(Y));

  rep(i, n) {
    int x, y, w;
    cin >> x >> y >> w;

    X[max(0, x - w)]++;
    X[min(W, x + w)]--;

    Y[max(0, y - w)]++;
    Y[min(H, y + w)]--;
  }

  REP(i, 1, 100005) {
    X[i] += X[i - 1];
    Y[i] += Y[i - 1];
  }

  bool a = true, b = true;
  REP(i, 0, W) {
    if (X[i] == 0)
      a = false;
  }

  REP(i, 0, H) {
    if (Y[i] == 0)
      b = false;
  }

  if (a || b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}