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

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

void tes() {
  while (1) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int t = 0; t < k; t++) {
      vector<int> tmp = a;
      for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
          if (a[j] >= abs(j - i))
            cnt++;
        }
        tmp[i] = cnt;
        cout << tmp[i] << " ";
      }
      cout << "\\n";
      a = tmp;
    }
  }
}

const int maxk = 100;
int n, k, a[200003], bit[200003];

void update(int x, int val) {
  while (x <= n) {
    bit[x] += val;
    x += x & -x;
  }
}

int sum(int x) {
  int ret = 0;
  while (x > 0) {
    ret += bit[x];
    x -= x & -x;
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //	tes();
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (k > maxk) {
    for (int i = 0; i < n; i++)
      cout << n << " ";
    cout << "\\n";
    return 0;
  }
  for (int t = 0; t < k; t++) {
    memset(bit, 0, sizeof bit);
    for (int i = 1; i <= n; i++) {
      update(max(1, i - a[i - 1]), 1);
      update(min(n + 1, i + a[i - 1] + 1), -1);
    }
    for (int i = 1; i <= n; i++)
      a[i - 1] = sum(i);
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
  cout << "\\n";
}

Error: TLE

Fixed submission:

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

void tes() {
  while (1) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int t = 0; t < k; t++) {
      vector<int> tmp = a;
      for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
          if (a[j] >= abs(j - i))
            cnt++;
        }
        tmp[i] = cnt;
        cout << tmp[i] << " ";
      }
      cout << "\\n";
      a = tmp;
    }
  }
}

const int maxk = 100;
int a[200003], tmp[200003];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //	tes();
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (k > maxk) {
    for (int i = 0; i < n; i++)
      cout << n << " ";
    cout << "\\n";
    return 0;
  }
  for (int t = 0; t < k; t++) {
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++) {
        if (a[j] >= abs(j - i))
          cnt++;
      }
      tmp[i] = cnt;
    }
    for (int i = 0; i < n; i++)
      a[i] = tmp[i];
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
  cout << "\\n";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= a; --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\\n"
#define lowbit(x) x & (-x)
const int N = 20000;
const int M = 1e9 + 7;

int a[110][200010];
int b[110][200010];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[0][i];
  }
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) {
      b[i + 1][max(1, j - a[i][j])]++;
      b[i + 1][min(n + 1, j + a[i][j] + 1)]--;
    }
    int t = 0, f = 1;
    for (int j = 1; j <= n; j++) {
      t += b[i + 1][j];
      a[i + 1][j] = t;
      if (a[i + 1][j] != n)
        f = 0;
    }
    if (f) {
      for (int j = 1; j <= n; j++)
        cout << a[i + 1][j] << ' ';
      return 0;
    }
  }
  for (int j = 1; j <= n; j++)
    cout << a[k][j] << ' ';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= a; --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\\n"
#define lowbit(x) x & (-x)
const int N = 20000;
const int M = 1e9 + 7;

int a[200010];

int b[20][200010];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    b[0][i] = a[i];
  }
  for (int i = 0; i <= k; i++) {
    int f = 1;
    for (int j = 1; j <= n; j++) {
      //			cout<<b[i][j]<<' ';
      if (b[i][j] != n)
        f = 0;
      for (int p = 0; p <= b[i][j]; p++) {
        if (j + p <= n)
          b[i + 1][j + p]++;
        if (p == 0)
          continue;
        if (j - p >= 1)
          b[i + 1][j - p]++;
      }
    }
    if (f == 1) {
      for (int j = 1; j <= n; j++) {
        cout << b[i][j] << ' ';
      }
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << b[k][i] << ' ';
  }
  return 0;
}
Problem p02647 (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 main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  vector<int> imo(n + 1);
  /*いもす法*/
  rep(j, min(k, (int)log2(n) + 100)) {
    imo = vector<int>(n + 1);
    rep(i, n) {
      imo[max(0, i - v[i])]++;
      imo[min(i + (v[i] + 1), n)]--;
    }
    int bef = 0;
    rep(i, n) {
      bef += imo[i];
      v[i] = bef;
    }
  }
  rep(i, n) cout << v[i] << " ";
  cout << endl;
  return 0;
}

Error: WA

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 main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  vector<int> imo(n + 1);
  /*いもす法*/
  rep(j, min(k, (int)log2(n) + 100)) {
    imo = vector<int>(n + 1);
    rep(i, n) {
      imo[max(0, i - v[i])]++;
      imo[i + min(v[i] + 1, n)]--;
    }
    int bef = 0;
    rep(i, n) {
      bef += imo[i];
      v[i] = bef;
    }
  }
  rep(i, n) cout << v[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, K;
  cin >> N >> K;
  if (log10(N) * 8 - 2 <= K) {
    for (int i = 0; i < N; i++) {
      cout << N;
      if (i == N - 1)
        cout << endl;
      else
        cout << ' ';
    }
    return 0;
  }
  vector<vector<int>> A(K + 1, vector<int>(N, 0));
  for (int &i : A[0])
    cin >> i;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < N; j++) {
      A[i + 1][max(0, j - A[i][j])]++;
      A[i + 1][min(N - 1, j + A[i][j]) + 1]--;
    }
    for (int j = 1; j < N; j++) {
      A[i + 1][j] += A[i + 1][j - 1];
    }
  }
  for (int i = 0; i < N; i++) {
    cout << A[K][i];
    if (i == N - 1)
      cout << endl;
    else
      cout << ' ';
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  if (log10(N) * 8 - 2 <= K) {
    for (int i = 0; i < N; i++) {
      cout << N;
      if (i == N - 1)
        cout << endl;
      else
        cout << ' ';
    }
    return 0;
  }
  vector<vector<int>> A(K + 1, vector<int>(N, 0));
  for (int &i : A[0])
    cin >> i;
  for (int i = 0; i < K; i++) {
    for (int k = 0; k < N; k++) {
      int l = min(N - 1, k + A[i][k]);
      for (int j = max(0, k - A[i][k]); j <= l; j++) {
        A[i + 1][j]++;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << A[K][i];
    if (i == N - 1)
      cout << endl;
    else
      cout << ' ';
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  vector<int> imos(N + 1);
  REP(i, N + 1) imos[i] = 0;
  REP(i, K) {
    int flag_s = 0;
    int flag_g = 0;
    REP(n, N) {
      int start = ceil((n + 1) - A[n] - 0.5);
      int end = floor((n + 1) + A[n] + 0.5);
      if (start < 1) {
        imos[0]++;
        flag_s++;
      } else {
        imos[start - 1]++;
      }

      if (end >= N) {
        imos[N]--;
        flag_g++;
      } else {
        imos[end]--;
      }
    }
    REP(m, N) {
      if (m == 0)
        A[m] = imos[m];
      else {
        A[m] = imos[m] + A[m - 1];
        imos[m - 1] = 0;
      }
    }
    imos[N - 1] = 0;
    if (flag_s == N && flag_g == N) {
      break;
    }
  }
  REP(i, N) { cout << A[i] << " "; }
  cout << endl;
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  vector<int> imos(N + 1);
  REP(i, N + 1) imos[i] = 0;
  REP(i, K) {
    REP(n, N) {
      int start = ceil((n + 1) - A[n] - 0.5);
      int end = floor((n + 1) + A[n] + 0.5);
      if (start < 1) {
        imos[0]++;
      } else {
        imos[start - 1]++;
      }

      if (end >= N) {
        imos[N]--;
      } else {
        imos[end]--;
      }
    }
    REP(m, N) {
      if (m == 0)
        A[m] = imos[m];
      else {
        A[m] = imos[m] + A[m - 1];
        imos[m - 1] = 0;
      }
    }
    imos[N - 1] = 0;
  }
  REP(i, N) { cout << A[i] << " "; }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
>;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v) {
  for (int i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {
  lli n, k;
  cin >> n >> k;
  vi ans(n + 2, 0), cnt(n + 2, 0), meme(n + 2, 0);
  rep(i, n) cin >> ans[i + 1];

  rep(i, min(k, (lli)41)) {
    swap(ans, cnt);
    ans = meme;
    for (int j = 1; j <= n; j++) {
      (j - cnt[j] > 0 ? ans[j - cnt[j]] += 1 : ans[0] += 1);
      (j + cnt[j] + 1 < n + 1 ? ans[j + cnt[j] + 1] -= 1 : ans[n + 1] -= 1);
    }
    for (int j = 1; j <= n; j++) {
      ans[j] = ans[j] + ans[j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i];
    if (i != n)
      cout << " ";
    else
      cout << endl;
  }
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
>;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v) {
  for (int i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {
  lli n, k;
  cin >> n >> k;
  vi ans(n + 2, 0), cnt(n + 2, 0), meme(n + 2, 0);
  rep(i, n) cin >> ans[i + 1];

  rep(i, k) {
    swap(ans, cnt);
    ans = meme;
    for (int j = 1; j <= n; j++) {
      (j - cnt[j] > 0 ? ans[j - cnt[j]] += 1 : ans[0] += 1);
      (j + cnt[j] + 1 < n + 1 ? ans[j + cnt[j] + 1] -= 1 : ans[n + 1] -= 1);
    }
    for (int j = 1; j <= n; j++) {
      ans[j] = ans[j] + ans[j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i];
    if (i != n)
      cout << " ";
    else
      cout << endl;
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  for (long long int j = 0; j < k; j++) {
    vector<long long int> ruiseki(n, 0);
    for (long long int i = 0; i < n; i++) {
      long long int l, r;
      l = max((long long int)0, i - a.at(i));
      r = min(n - 1, i + a.at(i));
      ruiseki.at(l)++;
      if (r + 1 > n - 1)
        continue;
      ruiseki.at(r + 1)--;
    }
    vector<long long int> pre(n, 0);
    bool all = true;
    pre.at(0) = ruiseki.at(0);
    if (pre.at(0) != n)
      all = false;
    // cout<<ruiseki.at(0)<<" ";
    for (long long int i = 1; i < n; i++) {
      pre.at(i) = pre.at(i - 1) + ruiseki.at(i);
      if (pre.at(i) != n)
        all = false;
      // cout<<ruiseki.at(i)<<" ";
    }
    // cout<<endl;
    a = pre;
    if (all)
      break;
  }

  for (long long int i = 0; i < n; i++) {
    cout << a.at(i);
    if (i != n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  for (long long int i = 0; i < k; i++) {
    vector<long long int> pre(n, 0);
    for (long long int j = 0; j < n; j++) {
      long long int hoge = a.at(j);
      long long int zero = 0;
      for (long long int k = max(zero, j - a.at(j));
           k <= min(n - 1, j + a.at(j)); k++) {
        pre.at(k)++;
      }
    }
    a = pre;
    vector<long long int> all(n, n);
    if (a == all) {
      break;
    }
  }
  for (long long int i = 0; i < n; i++) {
    cout << a.at(i);
    if (i != n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define rep0(i, n) for (ll i = 0; i <= (ll)(n); i++)
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 1);
  rep1(i, n) cin >> a[i];
  ll mx = min(k, (ll)log(n) + 1);
  rep1(ki, k) {
    vector<ll> b(n + 2);
    rep1(i, n) {
      ll l = max(i - a[i], (ll)1);
      ll r = min(i + a[i] + 1, n + 1);
      b[l]++;
      b[r]--;
    }
    rep0(i, n - 1) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }
  rep1(i, n) cout << a[i] << endl;
}
/*
5 1
1 0 0 1 0

5 2
1 0 0 1 0
*/

Error: TLE

Fixed submission:

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

int main() {
  int n, k, tmp;
  cin >> n >> k;
  vector<vector<double>> a(n, vector<double>(2));
  vector<vector<double>> d(n, vector<double>(2));
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a[i][0] = (i + 1) - tmp - 0.5;
    a[i][1] = (i + 1) + tmp + 0.5;
    d[i][0] = (i + 1) - tmp - 0.5;
    d[i][1] = (i + 1) + tmp + 0.5;
  }
  int b;
  int itr;
  vector<int> q(n);
  for (int j = 0; j < k; j++) {
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
      b = 0;
      for (int r = 0; r < n; r++) {
        q[r] = a[r][0];
      }
      auto itr = lower_bound(q.begin(), q.end(), i + 1);
      int m = itr - q.begin();

      for (int p = 0; p < m; p++) {
        if (i + 1 <= a[p][1]) {
          b++;
        }
      }
      d[i][0] = (i + 1) - b - 0.5;
      d[i][1] = (i + 1) + b + 0.5;
    }
    // copy
    for (int l = 0; l < n; l++) {
      a[l][0] = d[l][0];
      a[l][1] = d[l][1];
    }
  }

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      cout << a[i][1] - (i + 1) - 0.5;
    } else if (i == n - 1) {
      cout << " " << a[i][1] - (i + 1) - 0.5 << endl;
    } else {
      cout << " " << a[i][1] - (i + 1) - 0.5;
    }
  }
}
/*
5 1
1 0 0 1 0

5 2
1 0 0 1 0
*/
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;

  ll A[N];
  ll area[N + 1]; // N + 1は無視
  ll areaSum;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll tryMin = 1000;
  ll tryMinN = 1;
  while (tryMinN <= N) {
    tryMinN *= 2;
    tryMin++;
  }
  tryMin = min(tryMin, K);
  for (ll rep = 0; rep < tryMin; rep++) {
    for (ll i = 0; i < N; i++) {
      area[i] = 0;
    }
    for (ll i = 0; i < N; i++) {
      area[max(i - A[i], (ll)0)]++;
      area[min(i + A[i] + 1, N)]--;
    }
    areaSum = 0;
    for (ll i = 0; i < N; i++) {
      areaSum += area[i];
      A[i] = areaSum;
    }
  }

  for (ll i = 0; i < N; i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;

  ll A[N];
  ll area[N + 1]; // N + 1は無視
  ll areaSum;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (ll rep = 0; rep < K; rep++) {
    for (ll i = 0; i < N; i++) {
      area[i] = 0;
    }
    for (ll i = 0; i < N; i++) {
      area[max(i - A[i], (ll)0)]++;
      area[min(i + A[i] + 1, N)]--;
    }
    areaSum = 0;
    for (ll i = 0; i < N; i++) {
      areaSum += area[i];
      A[i] = areaSum;
    }
  }

  for (ll i = 0; i < N; i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  for (int j = 0; j < K; j++) {
    vector<ll> imos(N + 1, 0);
    for (int i = 0; i < N; i++) {
      imos[max(0, i - A[i])]++;
      imos[min(N, i + A[i] + 1)]--;
    }

    A[0] = imos[0];
    bool flag = false;
    if (A[0] == N)
      flag = true;
    for (int i = 1; i < N; i++) {
      imos[i] += imos[i - 1];
      A[i] = imos[i];
      if (A[i] != N)
        flag = false;
    }
    if (flag)
      break;
  }
  for (int i = 0; i < N; i++)
    cout << A[i] << " ";
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct SegTree {
  int leaf_node_num;
  int start_leaf_node_num;
  vector<int> node_value;

  SegTree(int input_num) {
    leaf_node_num = 1;
    while (leaf_node_num < input_num) {
      start_leaf_node_num = leaf_node_num;
      leaf_node_num *= 2;
    }

    for (int i = 0; i < 2 * leaf_node_num - 1; i++)
      node_value.push_back(0);
  }

  void query(int a, int b, int k = 0, int l = 0, int r = -1) {
    // 最初のクエリのとき
    if (r == -1)
      r = leaf_node_num;

    // [r, l)を[a, b)がすべて含んでいるとき
    if (a <= l && r <= b) {
      node_value[k]++;
      // cout << a << " " << b << " " << l << " " << r << " " << node_value[k]
      // << endl;
    } else if (r <= a || b <= l)
      ;
    else {
      // そうでないときは子ノードの最小値
      query(a, b, k * 2 + 1, l, (l + r) / 2);
      query(a, b, k * 2 + 2, (l + r) / 2, r);
    }
  }

  void sum(int k = 0) {
    node_value[k * 2 + 1] += node_value[k];
    node_value[k * 2 + 2] += node_value[k];
    if (k * 2 + 1 < int(node_value.size()))
      sum(k * 2 + 1);
    if (k * 2 + 2 < int(node_value.size()))
      sum(k * 2 + 2);
  }
};

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  for (int j = 0; j < K; j++) {
    SegTree tree(N);
    // cout << j << endl;
    for (int i = 0; i < N; i++) {
      tree.query(max(0, i - A[i]), min(N, i + A[i] + 1));
    }
    tree.sum();
    bool flag = true;
    for (int i = 0; i < N; i++) {
      A[i] = tree.node_value[tree.node_value.size() - tree.leaf_node_num + i];
      if (A[i] != N)
        flag = false;
    }
    // for (int i = 0; i < tree.node_value.size(); i++)
    //     cout << tree.node_value[i] << " ";
    // cout << endl;
    if (flag)
      break;
  }
  for (int i = 0; i < N; i++)
    cout << A[i] << " ";
}