Untitled
unknown
plain_text
2 years ago
1.1 kB
13
Indexable
#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;
for (ll i = 1; i < n - 1; ++i) {
tec -= (n - i) * (a[i].first - a[i - 1].first);
pred += (a[i].first - a[i - 1].first + 1) * i;
ans[a[i].second] = pred + tec + 1;
}
ans[a[n - 1].second] = pred + 1;
for (auto x: ans) {
cout << x << ' ';
}
cout << '\n';
}
}Editor is loading...