#include #include #include using namespace std; template struct BIT { const Abel UNITY_SUM = 0; vector dat; BIT(int n) : dat(n + 1, UNITY_SUM) { } // [1, n] inline void add(int i, Abel x) { while (i < dat.size()) { dat[i] += x; i += i & -i; } } inline Abel sum(int i) { // [1, i] Abel res = UNITY_SUM; while (i > 0) { res += dat[i]; i -= i & -i; } return res; } inline Abel sum(int a, int b) { return sum(b - 1) - sum(a - 1); } // [a, b) /* debug */ Abel operator[](int i) { return sum(i, i + 1); } void debug() { for (int i = 1; i < dat.size(); ++i) cout << sum(i, i + 1) << ","; cout << endl; } }; int main() { int n; cin >> n; vector a(n); for (int &ai: a) cin >> ai; vector b = a; sort(begin(b), end(b)); b.erase(unique(begin(b), end(b)), end(b)); long long res = 0; BIT bit(n); vector order(n); for (int i = 0; i < n; i++) { order[i] = lower_bound(begin(b), end(b), a[i]) - begin(b) + 1; res += bit.sum(order[i] + 1, n + 1); bit.add(order[i], 1); } cout << res << endl; for (int i = 0; i < n - 1; i++) { res -= bit.sum(1, order[i]); res += bit.sum(order[i] + 1, n + 1); cout << res << endl; } return 0; }