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

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
#define MP make_pair

short dp[5010][5010] = {};
int main() {
  int N, M, a, b, x, res, cnt;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> x;
    for (int j = 0; j <= x; j++) {
      dp[a + j][b] = max(dp[a + j][b], (short)(j + 1));
    }
  }

  res = 0;
  for (int i = 1; i <= N; i++) {
    cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (j != 1 && dp[i][j - 1] == 0) {
        cnt++;
      }
      dp[i][j] = max((short)(dp[i][j - 1] - 1), dp[i][j]);
    }
    if (dp[i][i] == 0)
      cnt++;
    res += cnt;
  }
  cout << N * (N + 1) / 2 - res << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
#define MP make_pair

int dp[5010][5010] = {};
int main() {
  int N, M, a, b, x, res, cnt;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> x;
    for (int j = 0; j <= x; j++) {
      dp[a + j][b] = max(dp[a + j][b], j + 1);
    }
  }

  res = 0;
  for (int i = 1; i <= N; i++) {
    cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (j != 1 && dp[i][j - 1] == 0) {
        cnt++;
      }
      dp[i][j] = max(dp[i][j - 1] - 1, dp[i][j]);
    }
    if (dp[i][i] == 0)
      cnt++;
    res += cnt;
  }
  cout << N * (N + 1) / 2 - res << endl;
  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> imos[5010];
  for (int i = 0; i <= n + 5; i++) {
    imos[i].resize(i + 5);
    for (int j = 0; j < i + 5; j++)
      imos[i][j] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    imos[a][b]++;
    imos[a][b + 1]--;
    imos[a + x + 1][b]--;
    imos[a + x + 2][b + 1]++;
    imos[a + x + 1][b + x + 2]++;
    imos[a + x + 2][b + x + 2]--;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i + 3; j++)
      imos[i][j] += imos[i][j - 1];

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i + 3; j++)
      imos[i][j] += imos[i - 1][j];

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i + 3; j++)
      imos[i][j] += imos[i - 1][j - 1];

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      cnt += (imos[i][j]) ? 1 : 0;
      //("%2d ",imos[i][j]);
    }
    // puts("");
  }
  printf("%d\\n", cnt);
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int imos[50050][5050];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    imos[a][b]++;
    imos[a][b + 1]--;
    imos[a + x + 1][b]--;
    imos[a + x + 2][b + 1]++;
    imos[a + x + 1][b + x + 2]++;
    imos[a + x + 2][b + x + 2]--;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      imos[i][j] += imos[i][j - 1];

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      imos[i][j] += imos[i - 1][j];

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      imos[i][j] += imos[i - 1][j - 1];

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      cnt += (imos[i][j]) ? 1 : 0;
      // printf("%2d ",imos[i][j]);
    }
    // puts("");
  }
  printf("%d\\n", cnt);
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 29)
#define MAX 5100
using namespace std;

int N, M;
// int g[MAX][MAX];

int main() {
  scanf("%d %d", &N, &M);
  vector<int> g[N + 5];
  rep(i, N + 5) g[i].resize(i + 5);
  rep(i, N + 5) rep(j, i + 1) g[i][j] = 0;
  rep(i, M) {
    int x, y, d;
    scanf("%d %d %d", &y, &x, &d);
    x--, y--;
    g[y][x]++, g[y + d + 2][x + 1]++, g[y + d + 1][x + d + 2]++;
    g[y][x + 1]--, g[y + d + 1][x]--, g[y + d + 2][x + d + 2]--;
  }

  rep(i, N + 2) rep(j, i + 2) if (j - 1 >= 0) g[i][j] += g[i][j - 1];
  rep(x, N + 2) REP(y, x, N + 2) if (y - 1 >= 0) g[y][x] += g[y - 1][x];
  rep(i, N + 2) {
    int y = i, x = 0;
    while (y <= N + 2 && x <= N + 2) {
      if (y - 1 >= 0 && x - 1 >= 0)
        g[y][x] += g[y - 1][x - 1];
      y++, x++;
    }
  }

  int ans = 0;
  rep(y, N + 2) rep(x, y + 2) if (g[y][x] > 0) ans++;
  cout << ans << endl;

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 29)
#define MAX 5100
using namespace std;

int N, M;
int g[MAX][MAX];

int main() {
  scanf("%d %d", &N, &M);
  assert(N <= MAX);
  rep(i, N + 5) rep(j, i + 1) g[i][j] = 0;
  rep(i, M) {
    int x, y, d;
    scanf("%d %d %d", &y, &x, &d);
    x--, y--;
    g[y][x]++, g[y + d + 2][x + 1]++, g[y + d + 1][x + d + 2]++;
    g[y][x + 1]--, g[y + d + 1][x]--, g[y + d + 2][x + d + 2]--;
  }

  rep(i, N + 5) rep(j, i + 5) if (j - 1 >= 0) g[i][j] += g[i][j - 1];
  rep(x, N + 5) REP(y, x, N + 5) if (y - 1 >= 0) g[y][x] += g[y - 1][x];
  rep(i, N + 5) {
    int y = i, x = 0;
    while (y <= N + 5 && x <= N + 5) {
      if (y - 1 >= 0 && x - 1 >= 0)
        g[y][x] += g[y - 1][x - 1];
      y++, x++;
    }
  }

  int ans = 0;
  rep(y, N + 5) rep(x, N + 5) if (g[y][x] > 0) ans++;
  cout << ans << endl;

  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
static vector<int> sum[5011];
int main() {
  for (int i = 0; i <= 5010; i++) {
    sum[i].resize(i + 10, 0);
  }
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    ++sum[a][b];
    --sum[a][b + 1];
    ++sum[a + x + 1][b + x + 2];
    --sum[a + x + 2][b + x + 2];
    ++sum[a + x + 2][b + 1];
    --sum[a + x + 1][b];
  }

  for (int i = 1; i <= N + 10; i++) {
    for (int j = 1; j <= i + 5; j++) {
      sum[i][j] += sum[i - 1][j - 1];
    }
  }
  for (int i = 1; i <= N + 10; i++) {
    for (int j = 1; j <= i + 5; j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }
  for (int i = 1; i <= N + 10; i++) {
    for (int j = 1; j <= i + 5; j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }

  int ret = 0, cnt = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= i; j++) {
      if (sum[i][j] != 0)
        ret++;
    }
  }
  cout << ret << endl;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int sum[5011][5011];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    ++sum[a][b];
    --sum[a][b + 1];
    ++sum[a + x + 1][b + x + 2];
    --sum[a + x + 2][b + x + 2];
    ++sum[a + x + 2][b + 1];
    --sum[a + x + 1][b];
  }

  for (int i = 1; i <= N + 10; i++) {
    for (int j = 1; j <= i + 5; j++) {
      sum[i][j] += sum[i - 1][j - 1];
    }
  }
  for (int i = 1; i <= N + 10; i++) {
    for (int j = 1; j <= i + 5; j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }
  for (int i = 1; i <= N + 10; i++) {
    for (int j = 1; j <= i + 5; j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }

  int ret = 0, cnt = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= i; j++) {
      if (sum[i][j])
        ret++;
    }
  }
  cout << ret << endl;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  int n, m;
  vector<int> nail[5000];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    nail[i].resize(i + 1);
  for (int i = 0; i < m; ++i) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    a -= 1, b -= 1;
    nail[a][b] = x + 1;
  }
  int ans = 0;
  for (int a = 0; a < n; ++a) {
    for (int b = 0; b <= a; ++b) {
      int l = a > 0 && b > 0 && (b - 1) <= (a - 1) ? nail[a - 1][b - 1] : 1;
      int r = a > 0 && (b) <= (a - 1) ? nail[a - 1][b] : 1;
      nail[a][b] = max(nail[a][b], max(l - 1, r - 1));
      if (nail[a][b] > 0)
        ans += 1;
    }
  }
  printf("%d\\n", ans);
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  int n, m;
  static int nail[5000][5000] = {0};
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    a -= 1, b -= 1;
    nail[a][b] = x + 1;
  }
  int ans = 0;
  for (int a = 0; a < n; ++a) {
    for (int b = 0; b < n; ++b) {
      int l = a > 0 && b > 0 ? nail[a - 1][b - 1] : 1;
      int r = a > 0 ? nail[a - 1][b] : 1;
      nail[a][b] = max(nail[a][b], max(l - 1, r - 1));
      if (nail[a][b] > 0)
        ans += 1;
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1 << 30;
int main() {
  int n, m;
  cin >> n >> m;
  vvi in(n + 3, vi(n + 3));
  while (m--) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    in[a][b]++;
    in[a][b + 1]--;
    in[a + c + 1][b]--;
    in[a + c + 1][b + c + 2]++;
    in[a + c + 2][b + 1]++;
    in[a + c + 2][b + c + 2]--;
  }
  int co = 0;
  rep(i, n + 2) rep(j, n + 2) in[i + 1][j + 1] += in[i][j];
  rep(i, n + 2) rep(j, n + 3) in[i + 1][j] += in[i][j];
  rep(i, n + 3) rep(j, n + 2) in[i][j + 1] += in[i][j];
  rep(i, n + 3) rep(j, n + 3) if (in[i][j]) co++;
  cout << co << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1 << 30;
int main() {
  int n, m;
  cin >> n >> m;
  vvi in(n, vi(n + 1));
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    rep(i, c + 1) {
      in[a + i][b]++;
      in[a + i][b + i + 1]--;
    }
  }
  int co = 0;
  rep(i, n) {
    int s = 0;
    rep(j, i + 1) {
      s += in[i][j];
      if (s)
        co++;
    }
  }
  cout << co << endl;
}
Problem p00497 (C++) — buggy submission, verdict: Runtime Error


#include <stdio.h>
#include <string.h>

int plate[5678][5678];

int n, m;

int main() {
  memset(plate, 0, sizeof(plate));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    --a;
    --b;
    ++plate[a][b];
    --plate[a][b + 1];
    --plate[a + x + 1][b];
    ++plate[a + x + 2][b + 1];
    ++plate[a + x + 1][b + x + 2];
    --plate[a + x + 2][b + x + 2];
  }
  for (int i = 1; i <= n + 2; ++i) {
    for (int j = 1; j <= n + 2; ++j) {
      plate[i][j] += plate[i - 1][j - 1];
    }
  }
  for (int i = 0; i <= n + 2; ++i) {
    for (int j = 1; j <= n + 2; ++j) {
      plate[i][j] += plate[i][j - 1];
    }
  }
  for (int i = 1; i <= n + 2; ++i) {
    for (int j = 0; j <= n + 2; ++j) {
      plate[i][j] += plate[i - 1][j];
    }
  }

  int ans = 0;
  for (int i = 0; i <= n + 2; ++i) {
    for (int j = 0; j <= n + 2; ++j) {
      if (plate[i][j] > 0)
        ++ans;
    }
  }

  printf("%d\\n", ans);
  return 0;
}

Error: 0

Fixed submission:


#include <stdio.h>
#include <string.h>

int plate[5002][5002];

int n, m;

int main() {
  memset(plate, 0, sizeof(plate));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    --a;
    --b;
    ++plate[a][b];
    --plate[a][b + 1];
    --plate[a + x + 1][b];
    ++plate[a + x + 2][b + 1];
    ++plate[a + x + 1][b + x + 2];
    --plate[a + x + 2][b + x + 2];
  }
  for (int i = 1; i <= n + 2; ++i) {
    for (int j = 1; j <= n + 2; ++j) {
      plate[i][j] += plate[i - 1][j - 1];
    }
  }
  for (int i = 0; i <= n + 2; ++i) {
    for (int j = 1; j <= n + 2; ++j) {
      plate[i][j] += plate[i][j - 1];
    }
  }
  for (int i = 1; i <= n + 2; ++i) {
    for (int j = 0; j <= n + 2; ++j) {
      plate[i][j] += plate[i - 1][j];
    }
  }

  int ans = 0;
  for (int i = 0; i <= n + 2; ++i) {
    for (int j = 0; j <= n + 2; ++j) {
      if (plate[i][j] > 0)
        ++ans;
    }
  }

  printf("%d\\n", ans);
  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  vector<vector<int>> masu(5005);
  for (int i = 0; i < masu.size(); i++) {
    for (int j = 0; j < i + 5; j++) {
      masu[i].push_back(0);
    }
  }

  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b, x;
    cin >> a >> b >> x;
    masu[a][b]++;
    masu[a][b + 1]--;
    masu[a + x + 1][b]--;
    masu[a + x + 1][b + x + 2]++;
    masu[a + x + 2][b + 1]++;
    masu[a + x + 2][b + x + 2]--;
  }

  // 左から右
  for (int i = 1; i <= n; i++) {
    for (int j = 2; j <= i; j++) {
      masu[i][j] += masu[i][j - 1];
    }
  }

  // 上から下
  for (int j = 1; j <= n; j++) {
    for (int i = j + 1; i <= n; i++) {
      masu[i][j] += masu[i - 1][j];
    }
  }

  // 左上から右下
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      masu[j][j - i + 1] += masu[j - 1][j - i];
    }
  }

  int num = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (masu[i][j] >= 1) {
        num++;
      }
    }
  }

  cout << num << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  vector<vector<int>> masu(5005);
  for (int i = 0; i < masu.size(); i++) {
    for (int j = 0; j < i + 6; j++) {
      masu[i].push_back(0);
    }
  }

  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b, x;
    cin >> a >> b >> x;
    masu[a][b] += 1;
    masu[a][b + 1] -= 1;
    masu[a + x + 1][b] -= 1;
    masu[a + x + 1][b + x + 2] += 1;
    masu[a + x + 2][b + 1] += 1;
    masu[a + x + 2][b + x + 2] -= 1;
  }

  // 左から右
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      masu[i][j] += masu[i][j - 1];
    }
  }

  // 上から下
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= n; i++) {
      masu[i][j] += masu[i - 1][j];
    }
  }

  // 左上から右下
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      masu[i][j] += masu[i - 1][j - 1];
    }
  }

  int num = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (masu[i][j] >= 1) {
        num++;
      }
    }
  }

  cout << num << endl;
  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

// AOJ 0574 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0574)
#include <cstdio>
#include <vector>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)

const int MAX_N = 5000;

int N, M;
std::vector<std::vector<int>> S(MAX_N + 2);

int main() {
  scanf("%d%d", &N, &M);

  rep(i, N + 2) S[i].resize(i + 2);

  rep(i, M) {
    int A, B, X;
    scanf("%d%d%d", &A, &B, &X);
    --A;
    --B;
    ++S[A][B];
    --S[A][B + 1];
    --S[A + X + 1][B];
    ++S[A + X + 1][B + X + 2];
    ++S[A + X + 2][B + 1];
    --S[A + X + 2][B + X + 2];
  }

  rep(i, N + 2) rep(j, i + 1) S[i][j + 1] += S[i][j];
  rep(i, N + 1) rep(j, i + 2) S[i + 1][j] += S[i][j];
  rep(i, N + 1) rep(j, i + 1) S[i + 1][j + 1] += S[i][j];

  int ans = 0;
  rep(i, N) rep(j, i + 1) if (S[i][j])++ ans;

  printf("%d\\n", ans);

  return 0;
}

Error: MLE

Fixed submission:

// AOJ 0574 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0574)
#include <cstdio>
#define rep(i, a) for (int i = 0; i < (a); ++i)

const int MAX_N = 5000;

int N, M;
int S[MAX_N + 3][MAX_N + 1];

int main() {
  scanf("%d%d", &N, &M);
  rep(i, M) {
    int A, B, X;
    scanf("%d%d%d", &A, &B, &X);
    --A;
    --B;
    ++S[A][B];
    --S[A][B + 1];
    --S[A + X + 1][B];
    ++S[A + X + 1][B + X + 2];
    ++S[A + X + 2][B + 1];
    --S[A + X + 2][B + X + 2];
  }

  rep(i, N) rep(j, N) S[i][j + 1] += S[i][j];
  rep(j, N) rep(i, N) S[i + 1][j] += S[i][j];
  rep(i, N) rep(j, N) S[i + j + 1][j + 1] += S[i + j][j];

  int ans = 0;
  rep(i, N) rep(j, N) if (S[i][j])++ ans;

  printf("%d\\n", ans);

  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF INT_MAX / 2
#define EPS 1.0e-7

#define MAX_N 5005

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

int N, M;

vector<int> cnt[MAX_N];

int main() {

  cin.sync_with_stdio(false);

  cin >> N >> M;

  for (int i = 0; i < N + 2; ++i)
    cnt[i].resize(i + 3);

  for (int i = 0; i < M; ++i) {

    int x, y, l;
    cin >> x >> y >> l;

    --x;
    --y;
    ++l;

    cnt[x][y] += 1;
    cnt[x + l + 1][y + 1] += 1;
    cnt[x + l][y + l + 1] += 1;

    cnt[x][y + 1] -= 1;
    cnt[x + l][y] -= 1;
    cnt[x + l + 1][y + l + 1] -= 1;
  }

  for (int i = 0; i < N; ++i)
    for (int j = 1; j <= i; ++j)
      cnt[i][j] += cnt[i][j - 1];

  for (int i = 0; i < N; ++i)
    for (int j = 1; i + j < N; ++j)
      cnt[i + j][i] += cnt[i + j - 1][i];

  for (int i = 0; i < N; ++i)
    for (int j = 1; i + j < N; ++j)
      cnt[i + j][j] += cnt[i + j - 1][j - 1];

  int ans = 0;

  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= i; ++j)
      if (cnt[i][j])
        ++ans;

  cout << ans << endl;

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF INT_MAX / 2
#define EPS 1.0e-7

#define MAX_N 5005
#define MAX_M 500005

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

int N, M;

int cnt[MAX_N][MAX_N];

int main() {

  cin.sync_with_stdio(false);

  cin >> N >> M;

  for (int i = 0; i < M; ++i) {

    int x, y, l;
    cin >> x >> y >> l;

    --x;
    --y;
    ++l;

    cnt[x][y] += 1;
    cnt[x + l + 1][y + 1] += 1;
    cnt[x + l][y + l + 1] += 1;

    cnt[x][y + 1] -= 1;
    cnt[x + l][y] -= 1;
    cnt[x + l + 1][y + l + 1] -= 1;
  }

  for (int i = 0; i < N; ++i)
    for (int j = 1; j < N; ++j)
      cnt[i][j] += cnt[i][j - 1];

  for (int i = 0; i < N; ++i)
    for (int j = 1; i + j < N; ++j)
      cnt[i + j][i] += cnt[i + j - 1][i];

  for (int i = 0; i < N; ++i)
    for (int j = 1; i + j < N; ++j)
      cnt[i + j][j] += cnt[i + j - 1][j - 1];

  int ans = 0;

  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= i; ++j)
      if (cnt[i][j])
        ++ans;

  cout << ans << endl;

  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

// AOJ 0574
#include <cstdio>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)

int N, M;
std::vector<std::vector<int>> map(5002);

int main() {
  scanf("%d%d", &N, &M);
  rep(i, N + 2) map[i].resize(i + 2);

  rep(i, M) {
    int A, B, X;
    scanf("%d%d%d", &A, &B, &X);
    --A;
    --B;
    ++map[A][B];
    --map[A][B + 1];
    --map[A + X + 1][B];
    ++map[A + X + 1][B + X + 2];
    ++map[A + X + 2][B + 1];
    --map[A + X + 2][B + X + 2];
  }

  rep(i, N + 2) repi(j, 1, i + 2) map[i][j] += map[i][j - 1];

  repi(i, 1, N + 2) rep(j, i + 1) map[i][j] += map[i - 1][j];

  repi(i, 1, N + 2) repi(j, 1, i + 1) map[i][j] += map[i - 1][j - 1];

  int ans = 0;
  rep(i, N) rep(j, i + 1) ans += map[i][j] ? 1 : 0;

  printf("%d\\n", ans);

  return 0;
}

Error: MLE

Fixed submission:

// AOJ 0574
#include <cstdio>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)

int N, M;
int map[5002][5001];

int main() {
  scanf("%d%d", &N, &M);
  rep(i, M) {
    int A, B, X;
    scanf("%d%d%d", &A, &B, &X);
    --A;
    --B;
    ++map[A][B];
    --map[A][B + 1];
    --map[A + X + 1][B];
    ++map[A + X + 1][B + X + 2];
    ++map[A + X + 2][B + 1];
    --map[A + X + 2][B + X + 2];
  }

  rep(i, N + 2) repi(j, 1, i + 2) map[i][j] += map[i][j - 1];

  repi(i, 1, N + 2) rep(j, i + 1) map[i][j] += map[i - 1][j];

  repi(i, 1, N + 2) repi(j, 1, i + 1) map[i][j] += map[i - 1][j - 1];

  int ans = 0;
  rep(i, N) rep(j, i + 1) ans += map[i][j] ? 1 : 0;

  printf("%d\\n", ans);

  return 0;
}