Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll, ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef set<int> st;
typedef set<char> stc;
typedef vector<int>::iterator itr;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for (int i = 0; i < (b); i++)
#define f00(b) for (int j = 0; j < (b); j++)
#define f1(b) for (int i = 1; i <= (b); i++)
#define f11(b) for (int j = 1; j <= (b); j++)
#define f2(a, b) for (int i = (a); i <= (b); i++)
#define f22(a, b) for (int j = (a); j <= (b); j++)
#define sq(a) a *a
#define cu(a) (sq(a) * a)
#define sf1(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define pf1(a) printf("%d\n", a)
#define pf2(a, b) printf("%d %d\n", a, b)
#define Last(i) ((i) & (-i))

const int mod = 1000000007;
const int maxn = (int)1e5 + 30;
const ll nnn = (ll)5e7 + 5;
const int inf = 1e9 + 9;
const ll INF = 1e18;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  ull a[maxn];
  ull b[maxn];
  ull n;
  ull ans[maxn];
  ull final = 0;

  cin >> n;

  memset(b, -1, sizeof(b));

  f1(n) cin >> a[i], b[a[i]]++;

  f1(n) {

    //	cout << i << ' ' << b[i] << ' ' << ((b[i] + 1) * b[i]) / 2  << endl;

    if (b[i] > 0)
      final += ((b[i] + 1) * b[i]) / 2;
  }

  f1(n) {

    ull s = a[i];
    ull ot = b[s] - 1;

    // cout << s << ' ' << ot << ' ' << ( ((b[s] + 1) * b[s]) / 2 ) << ' ' <<
    // (((ot + 1) * ot) / 2) << "\n";

    cout << final - (((b[s] + 1) * b[s]) / 2) + (((ot + 1) * ot) / 2) << "\n";
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll, ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef set<int> st;
typedef set<char> stc;
typedef vector<int>::iterator itr;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for (int i = 0; i < (b); i++)
#define f00(b) for (int j = 0; j < (b); j++)
#define f1(b) for (int i = 1; i <= (b); i++)
#define f11(b) for (int j = 1; j <= (b); j++)
#define f2(a, b) for (int i = (a); i <= (b); i++)
#define f22(a, b) for (int j = (a); j <= (b); j++)
#define sq(a) a *a
#define cu(a) (sq(a) * a)
#define sf1(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define pf1(a) printf("%d\n", a)
#define pf2(a, b) printf("%d %d\n", a, b)
#define Last(i) ((i) & (-i))

const int mod = 1000000007;
const int maxn = (int)2e5 + 30;
const ll nnn = (ll)5e7 + 5;
const int inf = 1e9 + 9;
const ll INF = 1e18;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  ull a[maxn];
  ull b[maxn];
  ull n;
  ull ans[maxn];
  ull final = 0;

  cin >> n;

  memset(b, -1, sizeof(b));

  f1(n) cin >> a[i], b[a[i]]++;

  f1(n) {

    //	cout << i << ' ' << b[i] << ' ' << ((b[i] + 1) * b[i]) / 2  << endl;

    if (b[i] > 0)
      final += ((b[i] + 1) * b[i]) / 2;
  }

  f1(n) {

    ull s = a[i];
    ull ot = b[s] - 1;

    // cout << s << ' ' << ot << ' ' << ( ((b[s] + 1) * b[s]) / 2 ) << ' ' <<
    // (((ot + 1) * ot) / 2) << "\n";

    cout << final - (((b[s] + 1) * b[s]) / 2) + (((ot + 1) * ot) / 2) << "\n";
  }

  return 0;
}