#include #include #include #include #include #include #include using namespace std; using ll = long long; struct BIT { BIT(int n) : b(n + 1), n(n) {} void add(int i, int v) { for (int k = i + 1; k <= n; k += k & -k) b[k] += v; } int sum(int k) { int s = 0; for (; k > 0; k -= k & -k) s += b[k]; return s; } vector b; int n; }; void coco(vector& v) { size_t n = v.size(); vector> t(n); for (int i = 0; i < n; i++) { t[i] = { v[i], i }; } sort(t.begin(), t.end()); int k = 0; for (int i = 0; i < n; i++) { if (i > 0 && t[i].first != t[i - 1].first) k++; v[t[i].second] = k; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } coco(a); ll s = 0; BIT bt(n); for (int i = 0; i < n; i++) { s += i - bt.sum(a[i] + 1); bt.add(a[i], 1); } for (int i = 0; i < n; i++) { cout << s << '\n'; s -= bt.sum(a[i]); s += n - bt.sum(a[i] + 1); } cout << flush; return 0; }