Untitled
unknown
plain_text
a year ago
1.4 kB
2
Indexable
Never
#include <bits/stdc++.h> #include <cmath> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll inf = 1e18 + 7, mod = 1e9 + 7; typedef long double ld; ld PI = acos(-1); int main() { freopen("input.txt", "r", stdin); cin.tie(0); ios::sync_with_stdio(0); ll t; cin >> t; while(t--) { ll n; cin >> n; vector<pair<ll, ll>> a(n); for (ll i = 0; i < n; ++i) { ll k; cin >> k; a[i] = {k,i}; } sort(a.begin(), a.end()); ll tec = 0; for (ll i = 1; i < n; ++i) { tec += (a[i].first - a[0].first + 1); } vector<ll> ans(n); ans[a[0].second] = tec + 1; ll pred = 0; // 1 3 4 // 8 = 1 + 3 + 4 // 6 = 1 + 2 + 3 // 7 = 1 + 2 + 4 // 1 3 4 tec = 3 + 4 for (ll i = 1; i < n - 1; ++i) { tec -= (n - i) * (a[i].first - a[i - 1].first + 1) - 1; pred += (a[i].first - a[i - 1].first + 1) * i; ans[a[i].second] = pred + tec + 1; } pred += (a[n - 1].first + 1 - a[n - 2].first) * (n - 1); ans[a[n - 1].second] = pred ; for (auto x: ans) { cout << x << ' '; } cout << '\n'; } }