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

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

typedef long long ll;

#define rep0(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define rep(i, a, b) for (ll i = (ll)a; i <= (ll)(b); i++)
#define rep0r(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define rep1r(i, n) for (ll i = (ll)(n); i > 0; i--)
#define repr(i, a, b) for (ll i = (ll)b; i >= (ll)(a); i--)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a *b / __gcd(a, b)

void solve() {
  ll n;
  ll cnt[200010];
  cin >> n;

  for (ll i = 0; i < 200010; i++) {
    cnt[i] = 0;
  }

  for (ll i = 2; i <= n; i++) {
    ll x = 0;
    cin >> x;
    cnt[x]++;
  }

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;

#define rep0(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define rep(i, a, b) for (ll i = (ll)a; i <= (ll)(b); i++)
#define rep0r(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define rep1r(i, n) for (ll i = (ll)(n); i > 0; i--)
#define repr(i, a, b) for (ll i = (ll)b; i >= (ll)(a); i--)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a *b / __gcd(a, b)

void solve() {
  ll n;
  vector<ll> a;
  cin >> n;

  rep(i, 0, n - 2) {
    ll x;
    cin >> x;
    a.push_back(x);
  }

  sort(a.begin(), a.end());

  rep1(i, n) {
    ll cnt = count(a.begin(), a.end(), i);
    cout << cnt << '\\n';
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

//
//  main.cpp
//  biggner20200419
//
//  Created by zer0 on 2020/04/19.
//  Copyright © 2020 zer0. All rights reserved.
//

#include <iostream>

int main(int argc, const char *argv[]) {
  int MAX_N = 2 * 100000;
  int n;
  std::cin >> n;
  int a[MAX_N];
  int b[MAX_N];

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

  for (int i = 1; i <= n; i++) {
    int m = a[i];
    b[m] = b[m] + 1;
  }

  for (int i = 1; i <= n; i++) {
    std::cout << b[i] << std::endl;
  }

  return 0;
}


Error: WA

Fixed submission:

//
//  main.cpp
//  biggner20200419
//
//  Created by zer0 on 2020/04/19.
//  Copyright © 2020 zer0. All rights reserved.
//

#include <iostream>

const long MAX_N = 2 * 10 ^ 5;

int main(int argc, const char *argv[]) {
  long n;
  std::cin >> n;
  long a[MAX_N], b[MAX_N];
  for (long i = 0; i < n; i++) {
    std::cin >> a[i];
    b[i] = 0;
  }

  for (long i = 0; i < n; i++) {
    b[a[i]]++;
  }

  for (long i = 0; i < n; i++) {
    std::cout << b[n] << std::endl;
  }

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

#include <stdio.h>
int ans[200000];
int main(void) {
  int n, i, x;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    scanf("%d", &x);
    ans[x - 1]++;
  }
  for (i = 0; i < n; i++) {
    printf("%d\\n", ans[i]);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a;
  int ans[100000];
  for (int i = 0; i < n; i++) {
    cin >> a;
    ans[a - 1]++;
  }
  for (int i = 0; i < n; i++)
    cout << ans[i] << " ";
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  int A[N - 1];
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
  }

  int ans[N];
  for (int i = 0; i < N; i++) {
    ans[i] = 0;
  }

  for (int i = 0; i < N - 1; i++) {
    int k = A[i] - 1;
    ans[k]++;
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int A[N - 1];
  int ans[N];
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
  }

  for (int i = 1; i < N + 1; i++) {
    ans[i] = 0;
    for (int j = i; j < N; j++) {
      if (A[j - 1] == i) {
        ans[i]++;
      }
    }
    cout << ans[i] << endl;
  }

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

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
using namespace std;
int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  long long n, arr[1000000], brr[1000000];
  cin >> n;

  for (long long i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  for (long long i = 0; i < n; i++) {
    brr[i] = 0;
  }

  for (long long i = 0; i < n - 1; i++) {
    brr[arr[i] - 1]++;
  }
  for (long long i = 0; i < n - 1; i++) {
    cout << brr[i] << "\\n";
    if (i == n - 2)
      break;
  }
  cout << brr[n - 1];
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
using namespace std;
int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n, arr[100000], brr[100000];
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    brr[i] = 0;
  }

  for (int i = 0; i < n; i++) {
    brr[arr[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << brr[i] << "\\n";
    if (i == n - 1)
      break;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

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

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> result(n);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    result[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << result[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);
// 桁数に注意 long long　にする

int main() {

  int n;
  cin >> n;

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);
// 桁数に注意 long long　にする

int main() {

  int n;
  cin >> n;

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

  auto copy = a;
  sort(all(copy));

  rep(i, n) {
    int ans = 0;
    rep(j, n - 1) {
      if (copy[j] == i + 1)
        ans++;
      if (copy[j] > i + 1)
        break;
    }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  int a[200000] = {0};
  rep(i, N - 1) {
    int temp;
    cin >> temp;
    temp--;
    a[temp]++;
  }
  rep(i, N) { cout << a[i] << endl; }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long N;
  cin >> N;
  int a;
  int B[N - 1];
  for (int i = 0; i < N - 1; i++) {
    cin >> a;
    B[i] = 0;
    for (int j = 1; j <= i + 1; j++) {
      if (a == j) {
        B[j - 1] += 1;
        break;
      }
    }
  }

  for (int i = 0; i < N - 1; i++) {
    cout << B[i] << 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> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
  }

  sort(A.begin(), A.end());

  int index = 0;
  for (int i = 1; i <= N; i++) {
    int count = 0;
    while ((size_t)index < A.size()) {
      if (A[index] > i) {
        break;
      }

      if (A[index] == i) {
        count++;
      }
      index++;
    }

    cout << count << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#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];
  }

  for (int i = 1; i <= N; i++) {
    cout << count(A.begin(), A.end(), i) << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x, a[n - 1];
  for (int i = 0; i < n - 1; i++) {
    a[i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    a[x - 1]++;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << endl;
  }
  cout << "0";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n - 1];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  int c;
  for (int i = 0; i < n - 1; i++) {
    c = 0;
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == i + 1)
        c++;
    }
    cout << c << endl;
  }
  cout << "0";
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

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

int main() {
  int n;
  cin >> n;
  vector<int> ans(n, 0);

  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    ans.at(a - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans.at(i) << endl;
  }
}

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


Fixed submission:

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

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

int main() {
  int n;
  cin >> n;
  vector<int> ans(n, 0);

  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    ans.at(a)++;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> data(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    data[i] = a;
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  for (int i = 0; i < n; i++) {
    int l = data.size();
    int count = 0;
    for (int j = l - 1; j >= 0; j--) {
      if (i == (data[j] - 1)) {
        count += 1;
      } else {
        break;
      }
    }
    for (int j = l - count; j < l; j++) {
      data.pop_back();
    }
    cout << count << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> data(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    data[i] = a;
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  for (int i = 0; i < n; i++) {
    int l = data.size();
    int count = 0;
    for (int j = 0; j < l; j++) {
      if (i == (data[j] - 1)) {
        count += 1;
      }
    }
    for (int j = l - count; j < l; j++) {
      data.pop_back();
    }
    cout << count << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

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

  int a[n], b[n];
  for (int i = 0; i < n; i++)
    b[i] = 0;

  for (int i = 1; i < n; i++) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << b[i] << endl;
  }
}


Error: -11

Fixed submission:

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

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

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

  int b[n];
  for (int i = 0; i < n; i++) {
    b[i] = 0;
    b[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << b[i] << endl;
  }
}
Problem p02707 (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;
const int INF = 1e9;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n + 5), ans(n + 5);
  for (int i = 2; i <= n; ++i)
    cin >> a[i], ans[a[i]]++;
  for (int i = 1; i <= n; ++i)
    cout << ans[i] << endl;
  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), ans(n);
  for (int i = 2; i <= n; ++i)
    cin >> a[i], ans[a[i]]++;
  for (int i = 1; i <= n; ++i)
    cout << ans[i] << 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;
  int arr[n];
  int ar[n] = {0};
  for (int i = 0; i < n - 1; i++)
    cin >> arr[i];
  for (int j = 0; j < n - 1; j++) {
    ar[arr[j]]++;
  }
  for (int i = 1; i < n; i++)
    cout << ar[i] << endl;
  cout << 0 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int ar[n];
  for (int i = 0; i < n - 1; i++)
    cin >> arr[i];
  for (int j = 1; j < n; j++) {
    int c = 0;
    for (int i = 0; i < n - 1; i++) {
      if (arr[i] == j)
        c++;
    }
    ar[j - 1] = c;
  }
  for (int i = 0; i < n - 1; i++)
    cout << ar[i] << endl;
  cout << 0 << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  /* for writing output to output.txt */
  int n;
  cin >> n;
  // long long sum = 0;
  vector<int> a(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    // sum += a[i];
  }
  vector<int> x(n);
  int one = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 1)
      one++;
  }
  // cout << one << endl;
  // int j = 2;
  // int count = 0;
  x[0] == one;
  for (int i = 0; i < n - 1; i++) {
    x[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++)
    cout << x[i] << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  /* for writing output to output.txt */
  int n;
  cin >> n;
  // long long sum = 0;
  vector<int> a(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    // sum += a[i];
  }
  int one = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 1)
      one++;
  }
  cout << one << endl;
  // int j = 2;
  // int count = 0;
  for (int i = 0; i < n - 1; i++) {
    int count = 0;
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == i + 2)
        count++;
    }
    cout << count << endl;
  }

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

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

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

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; ++i)
    cout << a[i] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; ++i)
    cout << a[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

const int maxn = 2e5 + 5;
int ind[maxn];

int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int x;
    cin >> x;
    ind[x]++;
  }
  for (int i = 1; i <= n; ++i) {
    cout << ind[i] << endl;
  }
}

Error: 0

Fixed submission:

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

const int maxn = 1e5 + 5;
int ind[maxn];

int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int x;
    cin >> x;
    ind[x]++;
  }
  for (int i = 1; i <= n; ++i) {
    cout << ind[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int a[200010];
int ans[200010];
int main() {
  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] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[100000];
int ans[100000];
int main() {
  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] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;

int N, M, A[200002] = {0}, i, j, k;

int main() {
  cin >> N;

  for (i = 1; i < N; i++) {
    cin >> k;
    A[k]++;
  }

  for (i = 1; i <= N; i++) {
    cout << A[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;

int N, M, A[20002] = {0}, i, j, k;

int main() {
  cin >> N;

  for (i = 1; i < N; i++) {
    cin >> k;
    A[k]++;
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }
  vector<int> count(N, 0);
  for (int i = 0; i < N - 1; i++) {
    count.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << count.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }
  vector<int> count(N);
  int t = 1;
  for (int i = 0; i < N; i++) {
    count.at(i) = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N; j++) {
      if (A.at(i) == j) {
        count.at(j - 1)++;
      }
    }
  }
  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 int long long
using namespace std;

signed main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 2; i <= n; i++)
    cin >> vec[i - 1];
  vector<int> buka(n);
  for (int i = 2; i <= n; i++) {
    buka[vec[i - 1] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << buka[i] << endl;
  }
  return 0;
}


Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

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

signed main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 2; i <= n; i++)
    cin >> vec[i];
  vector<int> buka(n);
  for (int i = 2; i <= n; i++) {
    buka[vec[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << buka[i] << endl;
  }

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


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

const int MAX_N = 2e5 + 5;

int n;
int cnt[MAX_N];

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

  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << "\\n";
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, a[200005];
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    int s = 0;
    for (int j = 2; j <= n; j++) {
      if (a[j] == i) {
        s++;
      }
    }
    cout << s << "\\n";
  }
  return 0;
}