#include #include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template class BIT { vector bit; public: BIT(int n): bit(vector(n+1, 0)){} T sum(int k){ T ret = 0; for (++k; k > 0; k -= (k & -k)) ret += bit[k]; return ret; } void add(int k, T x){ for (++k; k < bit.size(); k += (k & -k)) bit[k] += x; } }; int main() { int n; cin >> n; vector v(n); for (auto &&i : v) scanf("%d", &i); auto u = v; sort(u.begin(), u.end()); u.erase(unique(u.begin(), u.end()), u.end()); for (int i = 0; i < n; ++i) { v[i] = lower_bound(u.begin(),u.end(), v[i])-u.begin(); } BIT bit(n); ll ans = 0; for (int i = 0; i < n; ++i) { ans += i-bit.sum(v[i]); bit.add(v[i], 1); } vector S(u.size()+1); for (int i = 0; i < n; ++i) { S[v[i]+1]++; } for (int i = 0; i < u.size(); ++i) { S[i+1] += S[i]; } for (int i = 0; i < n; ++i) { printf("%lld\n", ans); ans += (n-S[v[i]+1]-S[v[i]]); } return 0; }