Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repll(i, n) for (long long int i = 0; i < n; i++)
#define fin(ans) cout << (ans) << endl
#define P 1000000007
#define STI(s) atoi(s.c_str()) // string to int
#define mp(p, q) make_pair(p, q)
#define Sort(a) sort(a.begin(), a.end())
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = INT_MAX;
const long long LLINF = 1LL << 60;
template <typename T_char> char ToUpper(char cX) { return toupper(cX); }
// g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a) {
  ll count = 0;
  for (ll i = 0; i < a; i++) {
    if (a == 0) {
      break;
    } else {
      a = a / 10;
      count++;
    }
  }
  return count;
}
#include <cstdint>

uintmax_t comb(unsigned int n, unsigned int r) {
  if (r * 2 > n)
    r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor = 1;
  for (unsigned int i = 1; i <= r; ++i) {
    dividend *= (n - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}
// 桁数のカウント
// pow(x,n) == x^n
// sum = accumulate(v.begin(),v.end(),0);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  /////////////////////////////////////////////////////

  int n;
  cin >> n;
  vi a(n - 1), ans(n);
  rep(i, n - 1) cin >> a[i];
  Sort(a);
  rep(i, n) ans[i] = 0;
  rep(i, n - 1) {
    for (int j = 1; j < n; j++) {
      if (a[i] == j) {
        ans[j - 1]++;
        break;
      }
    }
  }
  rep(i, n) cout << ans[i] << endl;

  //////////////////////////////////////////////////////
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repll(i, n) for (long long int i = 0; i < n; i++)
#define fin(ans) cout << (ans) << endl
#define P 1000000007
#define STI(s) atoi(s.c_str()) // string to int
#define mp(p, q) make_pair(p, q)
#define Sort(a) sort(a.begin(), a.end())
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = INT_MAX;
const long long LLINF = 1LL << 60;
template <typename T_char> char ToUpper(char cX) { return toupper(cX); }
// g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a) {
  ll count = 0;
  for (ll i = 0; i < a; i++) {
    if (a == 0) {
      break;
    } else {
      a = a / 10;
      count++;
    }
  }
  return count;
}
#include <cstdint>

uintmax_t comb(unsigned int n, unsigned int r) {
  if (r * 2 > n)
    r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor = 1;
  for (unsigned int i = 1; i <= r; ++i) {
    dividend *= (n - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}
// 桁数のカウント
// pow(x,n) == x^n
// sum = accumulate(v.begin(),v.end(),0);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  /////////////////////////////////////////////////////

  int n;
  cin >> n;
  vi a(n - 1), ans(n);
  rep(i, n - 1) cin >> a[i];
  Sort(a);
  ans[n - 1] = 0;
  rep(i, n - 1) { ans[a[i] - 1]++; }
  rep(i, n) cout << ans[i] << endl;

  //////////////////////////////////////////////////////
  return 0;
}