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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <iostream>  // cout, endl, cin
#include <math.h>    // sqrt
#include <string>    // string, to_string, stoi
#include <vector>    // vector
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> data(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> data.at(i);
  }
  vector<int> ans(N, 0);
  for (int x : data) {
    ans.at(x - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> boss(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> boss.at(i);
  }
  sort(boss.begin(), boss.end());
  for (int number = 1; number < N + 1; number++) {
    int ans = 0;
    for (int x : boss) {
      if (x == number) {
        ans++;
      } else if (x > number) {
        break;
      }
    }
    cout << ans << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  rep(i, n - 1) cin >> a[i];
  vector<int> b(n, 0);
  int cnt = 0;
  rep(i, n - 1) { b[a[i] - 1]++; }
  rep(i, n) cout << b[i] << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  rep(i, n - 1) cin >> a[i];
  vector<int> b(n, 0);
  rep(i, n - 1) rep(j, n) {
    if (a[i] == j + 1)
      b[j]++;
  }
  rep(i, n) cout << b[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

#define PI acos(-1.0)
#define pi 3.14159265359
#define fast_io                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define ll long long
#define el "\\n"

int main() {
  fast_io int n;
  cin >> n;

  int a[n + 2];
  int ans[n + 2] = {0};

  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    ans[a[i]]++;
  }

  for (int i = 1; i <= n; i++)
    cout << ans[i] << el;

  return 0;
}


Error: 0

Fixed submission:

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

#define PI acos(-1.0)
#define pi 3.14159265359
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ll long long
#define el "\\n"

const int t = 10001;
int a[t];
int ans[t];

int main() {
  fast_io int n;
  cin >> n;

  for (int i = 2; i <= n; i++)
    cin >> a[i];
  for (int i = 2; i <= n; i++)
    ans[a[i]]++;
  for (int i = 1; i <= n; i++)
    cout << ans[i] << el;

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

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
// #define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
#define asort(v, n) sort((v), (v + n))        // Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
typedef long long ll;

using namespace std;

signed main() {
  int n, b;
  cin >> n;
  vector<int> a(n);

  rep(i, n - 1) {
    cin >> b;
    a[b - 1]++;
  }

  rep(i, n) cout << a[i] << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// #define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
// #define int long long
#define asort(v, n) sort((v), (v + n))        // Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

signed main() {
  int n;
  cin >> n;
  int a[20005], ans[20005] = {0};
  rep(i, n - 1) cin >> a[i];

  rep(i, n) {
    int j = a[i] - i;
    ans[j]++;
  }

  rep(i, n) cout << ans[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC diagnostic error "-std=c++14"
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <cctype>
#include <cstdio>
using namespace std;
template <class code> inline code read(const code &a) {
  code x = 0;
  short w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    print(x / 10);
  putchar(x % 10 + 48);
}
int a[200005];
int main() {
  int n = read(n);
  for (int i = 1; i <= n - 1; i++) {
    int x = read(x);
    a[x]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\\n", a[i]);
  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC diagnostic error "-std=c++14"
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <cctype>
#include <cstdio>
using namespace std;
template <class code> inline code read(const code &a) {
  code x = 0;
  short w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    print(x / 10);
  putchar(x % 10 + 48);
}
int a[200005];
int main() {
  int n = read(n);
  for (int i = 1; i <= n; i++) {
    int x = read(x);
    a[x]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\\n", a[i]);
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// x番の組織が親組織に提出する枚数を返す
// childrenは組織の関係を表す2次元配列(参照渡し)
int count_report_num(vector<vector<int>> &children, int x) {
  // ベースケース
  if (children.at(x).size() == 0) {
    // 子組織から受け取ることは無いので0枚であることが確定している
    return 1;
  }

  // 再帰ステップ
  int sum = 0;
  for (int c : children.at(x)) {
    sum += 1;
    // sum += count_report_num(children, c);
  }
  sum += 1; // x番の組織の報告書の枚数(1枚)を足す
  return sum;
}

// これ以降の行は変更しなくてよい

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

  vector<int> p(N); // 各組織の親組織を示す配列
  p.at(0) = -1; // 0番組織の親組織は存在しないので-1を入れておく
  for (int i = 1; i < N; i++) {
    cin >> p.at(i);
    p.at(i)--;
  }

  // 組織の関係から2次元配列を作る
  vector<vector<int>> children(N); // ある組織の子組織の番号一覧
  for (int i = 1; i < N; i++) {
    int parent = p.at(i);             // i番の親組織の番号
    children.at(parent).push_back(i); // parentの子組織一覧にi番を追加
  }

  // 各組織について、答えを出力
  for (int i = 0; i < N; i++) {
    cout << count_report_num(children, i) - 1 << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> p.at(i);
  }

  for (int i = 1; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < N - 1; j++) {

      if (p.at(j) == i) {
        sum++;
      }
    }
    cout << sum << endl;
  }

  cout << 0 << endl;

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

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

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

  vector<int> p(N);
  p.at(0) = 1;
  for (int i = 1; i < N; i++) {
    cin >> p.at(i);
  }

  vector<int> children(N);
  for (int x : p) {
    children.at(x - 1)++;
  }
  children.at(0)--;
  for (int i = 0; i < N; i++) {
    cout << children.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

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

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

  vector<int> p(N);
  p.at(0) = -1;
  for (int i = 1; i < N; i++) {
    cin >> p.at(i);
  }

  vector<int> children(N);
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (p.at(i) == j) {
        children.at(j - 1)++;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << children.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> upper(N - 1);
  vector<int> lower(N);

  for (int i = 0; i < (N - 1); i++) {

    cin >> upper.at(i);

    int j = upper.at(i);

    lower.at(j - 1) += 1;
  }

  for (int i = 0; i < (N - 1); i++) {
    cout << lower.at(i) << endl;
  }
  cout << 0 << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> upper(N - 1);
  vector<int> lower(N);

  for (int i = 0; i < (N - 1); i++) {
    cin >> upper.at(i);

    for (int j = 0; j < N; j++) {
      if (upper.at(i) == (j + 1)) {
        lower.at(j) += 1;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << lower.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  unordered_map<int, int> mp;
  for (int i = 0; i < (int)a.size(); i++)
    mp[a[i]]++;
  for (int i = 1; i <= n; i++) {
    if (mp.find(i) != mp.end())
      cout << mp[i];
    else
      cout << 0;
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  unordered_map<int, int> mp;
  for (int i = 0; i < a.size(); i++)
    mp[a[i]]++;
  for (int i = 1; i <= n; i++) {
    if (mp.find(i) != mp.end())
      cout << mp[i];
    else
      cout << 0;
    cout << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, (n - 1)) cin >> a[i];

  vector<int> ans(n);
  rep(i, n) ans[i] = 0;
  rep(i, n - 1) { ans[(a[i] - 1)]++; }

  rep(i, n) cout << ans[i] << "\\n";

  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, (n - 1)) cin >> a[i];

  vector<int> ans(n);
  rep(i, n) ans[i] = 0;
  rep(i, n) { ans[a[i] - 1]++; }

  rep(i, n) cout << ans[i] << '\\n';

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  rep(i, n - 1) cin >> a.at(i);

  map<int, int> buka;
  rep(i, n) buka[i] = 0;

  rep(i, n - 1) buka[a.at(i) - 1]++;

  rep(i, n) cout << buka[i] << endl;
}

Error: TLE

Fixed submission:

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

int n, a[200000 - 1], buka[200000];

int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == i + 1)
        buka[i]++;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << buka[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, bossNumber;
  cin >> N;
  vector<int> bossList(N);
  for (int i = 0; i < (N - 1); i++) {
    cin >> bossNumber;
    bossList.at(bossNumber - 1) = bossList.at(bossNumber - 1) + 1;
  }
  for (int i = 0; i < N; i++) {
    cout << bossList.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> bossList(N - 1);
  for (int i = 0; i < (N - 1); i++) {
    cin >> bossList.at(i);
  }
  for (int i = 0; i < N; i++) {
    cout << count(bossList.begin(), bossList.end(), i + 1);
    cout << " " << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod = 1e9 + 7;
const db eps = 1e-9;
const ll maxn = 1e5 + 1;
const ll inf = LLONG_MAX;

#define mp make_pair
#define pb push_back
#define endl "\\n"
#define deb(x) cout << #x << " " << x << endl

int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  ll n;
  cin >> n;
  vector<ll> cnt(n + 1, 0);

  for (ll i = 0, tmp; i < n - 1; ++i) {
    cin >> tmp;
    cnt[tmp]++;
  }

  for (ll i = 1; i <= n; ++i)
    cout << cnt[i] << endl;
}

Error: 0

Fixed submission:

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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod = 1e9 + 7;
const db eps = 1e-9;
const ll maxn = 1e5 + 1;
const ll inf = LLONG_MAX;

#define mp make_pair
#define pb push_back
#define endl "\\n"
#define deb(x) cout << #x << " " << x << endl

int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, cnt[maxn];
  cin >> n;

  for (ll i = 0, tmp; i < n - 1; ++i)
    cin >> tmp, cnt[tmp]++;

  for (ll i = 1; i <= n; ++i)
    cout << cnt[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  int p;
  vector<int> A(N, 0);
  for (int i = 1; i < N; i++) {
    cin >> p;
    A[p - 1] += 1;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 1; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= N; i++) {
    int p = count(A.begin(), A.end(), i);
    cout << p << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <regex>
#include <set>
#include <string>
#include <vector>

using namespace std;

struct Employee {
  int id;
  int boss;
};

int main() {
  int n;
  std::cin >> n;
  std::vector<int> data(n, 0);

  for (int i = 0; i < n - 1; i++) {
    int a;
    std::cin >> a;
    data[a - 1]++;
  }

  for (auto x : data) {
    std::cout << x << std::endl;
  }

  return EXIT_SUCCESS;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <regex>
#include <set>
#include <string>
#include <vector>

using namespace std;

struct Employee {
  int id;
  int boss;
};

int main() {
  int n;
  std::vector<int> data;
  std::cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a;
    std::cin >> a;
    data.push_back(a);
  }

  for (int i = 1; i <= n + 1; i++) {
    std::cout << std::count_if(data.begin(), data.end(), [i](auto x) {
      return x == i;
    }) << std::endl;
    data.erase(data.end(), std::remove_if(data.begin(), data.end(),
                                          [i](auto x) { return x == i; }));
  }

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

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

int a[200010];
int ans[200010];

int main() {

  int n, flag, anss;
  cin >> n;
  for (int i = 2; i <= n; i++) // 1 teke n porjonto number moddhe input gula
                               // kotobar ache seta evabe ber korbo
    cin >> a[i];
  // cout<<a[0];
  for (int i = 2; i <= n; i++)
    ans[a[i]]++;
  for (int i = 1; i <= n; i++)
    cout << ans[i] << endl;
}


Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  int n, flag = 0, humty;
  cin >> n;
  vector<int> v(n);
  vector<int> g(n);
  for (int i = 0; i < g.size() - 1; i++) {
    cin >> g[i];
    // cout<<g[i]<<endl;
  }

  for (int i = 0; i < v.size(); i++) {
    v[i] = 0;
    // cout<<v[i]<<endl;
  }

  for (int i = 0; i < g.size(); i++) {
    humty = g[i];
    v[humty - 1] = count(g.begin(), g.end(), g[i]);
  }

  for (int i = 0; i < v.size(); i++)
    cout << v[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> boss(N - 1);
  for (int i = 0; i < N - 1; i++)
    cin >> boss.at(i);
  vector<int> count(N);
  for (int i = 0; i < N - 1; i++) {
    int a;
    a = boss.at(i) - 1;
    count.at(a)++;
  }
  for (int i = 0; i < N; i++)
    cout << count.at(i) << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 5)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> boss(N);
  for (int i = 0; i < N; i++)
    cin >> boss.at(i);
  vector<int> count(N);
  for (int i = 0; i < N; i++) {
    int a;
    a = boss.at(i) - 1;
    count.at(a)++;
  }
  for (int i = 0; i < N; i++)
    cout << count.at(i) << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define for0(i, b) for (int i = 0; i < b; i++)
#define for1(i, b) for (int i = 1; i <= b; i++)
#define reps(i, a, b) for (int i = a; i < b.length(); i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;

int main() {
  int n, val;
  cin >> n;
  std::vector<int> v(n + 1, 0);

  for (int i = 2; i <= n; i++) {
    cin >> val;
    v[val]++;
  }

  for (int i = 1; i <= n; i++)
    cout << v[i] << endl;

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
#define for0(i, b) for (int i = 0; i < b; i++)
#define for1(i, b) for (int i = 1; i <= b; i++)
#define reps(i, a, b) for (int i = a; i < b.length(); i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;

int main() {
  int n, val;
  std::vector<int> v(n, 0);

  cin >> n;

  for (int i = 2; i <= n; i++) {
    cin >> val;
    v[val]++;
  }

  for (int i = 1; i <= n; i++)
    cout << v[i] << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n - 1);
  rep(i, n - 1) {
    cin >> a[i];
    a[i]--;
  }
  vector<ll> count(n);

  rep(i, n - 1) { count[a[i]]++; }
  rep(i, n) { cout << count[i] << endl; }
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  vector<ll> count(n);

  rep(i, n) { count[a[i]]++; }
  rep(i, n) { cout << count[i] << endl; }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int j = 0, k = 1;
  a[0] = 0;
  for (int i = 1; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    b[i] = 0;

  sort(a, a + n);
  // for (int i = 0; i < n; i++) cout << a[i];

  while (1) {
    // if (k == n) {
    //     j += 1;
    //     k = 1;
    // }
    if (a[k] == j + 1) {
      b[j]++;
      k++;
    } else {
      // j += 1;
      j++;
    }
    if (j == n || k == n)
      break;
  }

  for (int i = 0; i < n; i++)
    cout << b[i] << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int j = 0, k = 1;
  a[0] = 0;
  for (int i = 1; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    b[i] = 0;

  // sort(a,a+n);
  // for (int i = 0; i < n; i++) cout << a[i];

  while (1) {
    if (k == n) {
      j += 1;
      k = 1;
    }
    if (a[k] == j + 1) {
      b[j]++;
      k++;
    } else {
      // j += 1;
      k++;
    }
    if (j == n - 1)
      break;
  }

  for (int i = 0; i < n; i++)
    cout << b[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define int long long

void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  fastio();
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    a--;
    v[a]++;
  }
  for (int i = 0; i < n; i++)
    cout << v[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define int long long

void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int32_t main() {
  fastio();
  int m;
  cin >> m;
  int n = m - 1;
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    int in;
    cin >> in;
    v.push_back(in);
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= m; ++i) {
    int f = count(v.begin(), v.end(), i);
    cout << f << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {
  int i, n;
  int *C;

  cin >> n;
  C = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    C[i] = 0;
  }

  for (i = 0; i < n - 1; i++) {
    int k;
    cin >> k;
    C[k - 1]++;
  }

  for (i = 0; i < n; i++) {
    cout << C[i] << endl;
  }

  free(C);
}


Error: 0

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {
  int i, n;
  int *C;

  cin >> n;
  C = (int *)malloc(sizeof(int));
  for (i = 0; i < n; i++) {
    C[i] = 0;
  }

  for (i = 0; i < n - 1; i++) {
    int k;
    cin >> k;
    C[k - 1]++;
  }

  for (i = 0; i < n; i++) {
    cout << C[i] << endl;
  }

  free(C);
}