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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007      // 10^9+7
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  // os << '{';
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : "\\n");
  }
  // os << '}';
  return os;
}

int main() {
  ll n;
  cin >> n;
  vi a(n - 1);
  vi b(n);
  cin >> a;
  rep(i, n - 1) {
    a[i]--;
    b[a[i]]++;
  }
  cout << b << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007      // 10^9+7
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  // os << '{';
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : "\\n");
  }
  // os << '}';
  return os;
}

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

#include <bits/stdc++.h>
#define lint long long int
using namespace std;
int main() {
  lint n = 0;
  cin >> n;
  vector<lint> a(n);
  map<lint, lint> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    a[i]--;
  }
  for (int i = 0; i < n; i++) {
    m[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cout << m[i] << endl;
  }
  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

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

#include "iostream"
using namespace std;

int main() {

  int N;
  int A[200001] = {0};
  int ans[200001] = {0};

  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] << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include "iostream"
using namespace std;

int main() {

  int N;
  int A[200001] = {0};
  int sum = 0;

  cin >> N;

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

  for (int j = 1; j <= N; j++) {
    for (int i = 2; i <= N; i++) {

      if (j == A[i])
        sum++;
    }

    cout << sum << "\\n";
    sum = 0;
  }

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

#include <iostream>

using namespace std;

int main() {
  long long N;

  cin >> N;

  long long A[N];

  long long B[N];

  for (int ix = 0; ix < N; ix++) {

    B[ix] = 0;
  }

  A[0] = 0;

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

    B[A[i] - 1]++;
  }

  for (int j = 0; j < N; j++) {

    cout << B[j] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long long N;

  cin >> N;

  long long A[N];

  A[0] = 0;

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

  for (int j = 0; j < N; j++) {

    long long count = 0;
    for (int k = j + 1; k < N; k++) {

      if (A[k] == j + 1) {

        count++;
      }
    }
    cout << count << endl;
  }

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

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

/// THEOVE46

#define PI 2 * acos(0.0)
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define gap " "
#define nn "\\n"

typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define sc(n) sf("%d", &n);
#define pc(n) pf("%d", n);
#define scf(f) sf("%f", &f);
#define pcf(f) pf("%f", f);
#define FOR(a, n) for (int i = a; i < n; i++)
#define RFOR(a, n) for (int i = a; i > n; i--)
#define TEST(test) for (int ove = 0; ove < test; ove++)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define all(x) (x).begin(), (x).end()
#define fap(x) cout << __LINE__ << " says: " << #x << " = " << x << "\\n"
#define FastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const ll INF = 2000000000000000000LL;
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;

/// THEOVE46

int main() {
  FastIO;
  ll n, i, j, t, x;
  cin >> n;
  ll a[n + 1] = {0};
  for (t = 0; t < n - 1; t++) {
    cin >> x;
    a[x]++;
  }
  for (i = 1; i <= n; i++)
    cout << a[i] << nn;

  return 0;
}

///   check for integer overflow, array bounds
///   check for n=1
///   - - - The Ove 46


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int arr[2 * 100000];
  int cnta[2 * 100000] = {0};
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n - 1);
  int zero = 0, zeroi;
  for (int i = 0; i < n - 1; i += zeroi) {
    zeroi = 0;
    int cnt = 0;
    int a = arr[i];
    if (a == 0)
      continue;
    int start = 0, end = n - 2, mid;
    while (start <= end) {
      mid = (start + zero + end) / 2;

      if (arr[mid] == a) {
        cnt++;
        arr[mid] = 0;
        zero++;
        zeroi++;
        sort(arr, arr + n - 1);
      } else if (arr[mid] < a) {
        start = mid + 1;
      } else {
        end = mid - 1;
      }
    }
    if (a != 0)
      cnta[a - 1] = cnt;
  }
  for (int i = 0; i < n; i++) {
    cout << cnta[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, k, a, c, m, i, j = 0, p, q;
  cin >> n;
  long long int ara[n] = {};
  for (i = 0; i < n - 1; i++) {
    cin >> a;
    ara[a - 1]++;
  }
  for (i = 0; i < n; i++) {
    cout << ara[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, k, a, c, m, i, j = 0, p, q;
  cin >> n;
  long long int ara[n - 1];
  for (i = 0; i < n - 1; i++) {
    cin >> ara[i];
  }
  for (j = 1; j <= n; j++) {
    c = 0;
    for (i = 0; i < n - 1; i++) {
      if (j == ara[i])
        c++;
    }
    cout << c << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define longlongvector vector<long long>
#define intvector vector<int>
#define size size()
using namespace std;

int n, m, k;

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

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

  // system("pause");
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define longlongvector vector<long long>
#define intvector vector<int>
#define size size()
using namespace std;

int n, m, k;

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

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

  // system("pause");
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int A;
  vec.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> A;
    vec.at(i) = A;
  }
  sort(vec.begin(), vec.end());
  int counter;
  int start = 0;
  for (int i = 0; i < N; i++) {
    counter = 0;
    for (int j = start; j < N; j++) {
      if (vec.at(j) == i + 1)
        counter++;
      if (vec.at(j) > i + 1)
        break;
    }
    cout << counter << endl;
    start += counter;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int A;
  vec.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> A;
    vec.at(i) = A;
  }
  sort(vec.begin(), vec.end());
  int counter;
  int start = 0;
  for (int i = 0; i < N; i++) {
    counter = 0;
    for (int j = start; j < N; j++) {
      if (vec.at(j) == i + 1)
        counter++;
    }
    cout << counter << endl;
    start += counter;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<int> b(a - 1), c(a);
  for (int i = 0; i < a - 1; i++) {
    cin >> b.at(i);
    c.at(b.at(i) - 1)++;
  }
  for (int i = 0; i < a; i++) {
    cout << c.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 <iostream>
#include <vector>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<int> b(a), c(a);
  for (int i = 0; i < a; i++) {
    cin >> b.at(i);
    c.at(b.at(i) - 1)++;
  }
  for (int i = 0; i < a; i++) {
    cout << c.at(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 < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) a[i] = 0;
  rep(i, n - 1) {
    int x;
    cin >> x;
    a[x - 1] += 1;
  }
  rep(i, n) cout << a[i] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \\
  ;                                                                            \\
  for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
  int n;
  cin >> n;
  int a[n - 1];
  rep(i, n - 1) cin >> a[i];
  rep(i, n) {
    int cnt = 0;
    for (int j = i; j < n - 1; j++) {
      if (a[j] == i + 1)
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  vector<int> ans(N, 0);

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

  for (int a : ans) {
    cout << a << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  cin >> N;

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

  for (int a : ans) {
    cout << a << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int main() {
  // 自分の回答
  // int n;
  // cin >> n;
  // vector<int> a(n-1);
  // vector<int> b(n);
  // for (int i=0;i<n-1;i++){
  //     cin >> a[i];
  //     b[i] = 0;
  // }
  // b[n] = 0;
  // for (int i=0;i<n-1;i++){
  //     b[a[i]-1]++;
  // }
  // for (int i=0;i<n;i++){
  //     cout << b[i] << endl;
  // }
  // return 0;

  // 正解
  int n;
  cin >> n;
  vector<int> ans(n);
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    ans[a - 1]++;
  }
  for (int x : ans) {
    cout << x << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int main() {
  // 自分の回答
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> b(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    b[i] = 0;
  }
  b[n] = 0;
  for (int i = 0; i < n - 1; i++) {
    b[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << b[i] << endl;
  }
  return 0;

  // 正解
  // int n;
  // cin >> n;
  // vector<int> ans(n);
  // for (int i = 0; i < n-1; i++) {
  //     int a;
  //     cin >> a;
  //     ans[a-1]++;
  // }
  // for (int x : ans) {
  //     cout << x << endl;
  // }
  // return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<int> a(200010);
  vector<int> ans(200010);
  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;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> ans(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;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int arr[200020];

int main() {
  int n, a;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a;
    arr[a]++;
  }

  for (int i = 1; i < n; i++) {
    cout << arr[i] << endl;
  }
  cout << "0" << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int count[2 * 10 ^ 5 + 1] = {0};
  int arr[2 * 10 ^ 5 + 1];
  for (int i = 1; i < n; i++) {
    cin >> arr[i];
    count[arr[i]]++;
  }
  for (int i = 1; i < n; i++) {
    cout << count[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;
  int a[N];
  vector<int> b(N + 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cout << b[i + 1] << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N - 1; i++)
    cin >> a[i];
  for (int i = 1; i < N + 1; i++) {
    int s = 0;
    for (int j = N - 2; j >= 0; j--) {
      if (a[j] == i)
        s++;
      if (j + 2 < i)
        break;
    }
    cout << s << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, s, n) for (ll(i) = (s); (i) < (n); (i)++)
#define repd(i, n, s) for (ll(i) = (n - 1); (i) >= (s); (i)--)
#define all(x) x.begin(), x.end()
#define size(x) ((ll)(x).size()
#define PB push_back

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

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


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

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

#define rep(i, s, n) for (ll(i) = (s); (i) < (n); (i)++)
#define repd(i, n, s) for (ll(i) = (n - 1); (i) >= (s); (i)--)
#define all(x) x.begin(), x.end()
#define size(x) ((ll)(x).size()
#define PB push_back

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

#define _GLIBCXX_DEBUG // TLEの原因になるので注意！！！！！！！！！！！
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// #define int long long

// cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
// const ll INF = 1LL << 60;
// typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

bool chmn(int &a, int b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

int A[200005];

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a;
    cin >> a;
    a--;
    A[a]++;
  }
  rep(i, n) { cout << A[i] << endl; }
  return 0;
}


Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG // TLEの原因になるので注意！！！！！！！！！！！
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// #define int long long

// cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
// const ll INF = 1LL << 60;
// typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

bool chmn(int &a, int b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

int A[20005];

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (i = a; i < n; i++)
#define per(i, a, n) for (i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE 1000001
#define ONLINE_JUDGE
#define rd
#define PI acos(-1)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
auto clk = clock();
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int main() {

  int i, n, freq[200005];
  memset(freq, 0, sizeof(freq));
  cin >> n;
  rep(i, 1, n) {
    int x;
    cin >> x;
    freq[x - 1]++;
  }
  rep(i, 0, n) cout << freq[i] << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (i = a; i < n; i++)
#define per(i, a, n) for (i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE 1000001
#define ONLINE_JUDGE
#define rd
#define PI acos(-1)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
auto clk = clock();
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int main() {

  int i, n, freq[100005];
  memset(freq, 0, sizeof(freq));
  cin >> n;
  rep(i, 1, n) {
    int x;
    cin >> x;
    freq[x - 1]++;
  }
  rep(i, 0, n) cout << freq[i] << "\\n";
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <map>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(n, 0);
  for (int i = 1; i < n; i++)
    cin >> a[i];

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

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <map>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> cnt(n, 0);
  for (int i = 1; i < n; i++)
    cin >> a[i];

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

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

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

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

int main() {
  int ar[1000000] = {0};
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int temp;
    cin >> temp;
    ++ar[temp];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d\\n", ar[i]);
  }
}

Error: 0

Fixed submission:

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

int main() {
  int ar[100000] = {0};
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int temp;
    cin >> temp;
    ++ar[temp];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d\\n", ar[i]);
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n = 0;
  cin >> n;

  vector<int> ai;
  ai.resize(n - 1);
  vector<int> bi;
  bi.resize(n);

  for (int i = 0; i < n; i++) {
    bi[i] = 0;
  }

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

  for (int i = 0; i < n - 1; i++) {
    bi[ai[i] - 1]++;
  }

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

Error: -6
double free or corruption (out)


Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n = 0;
  cin >> n;

  vector<int> ai;
  ai.resize(n);
  vector<int> bi;
  bi.resize(n);

  for (int i = 0; i < n; i++) {
    bi[i] = 0;
  }

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

  for (int i = 0; i < n; i++) {
    bi[ai[i] - 1]++;

    cout << bi[i] << endl;
  }
}