Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- #define ff first
- #define ss second
- int main()
- {
- _test
- {
- ll int n;
- cin>>n;
- vector<ll int> x(n);
- for(auto &e: x)
- cin>>e;
- vector<pair<ll int, int>> vp;
- for(int i=0; i<n; i++)
- vp.pb({x[i], i});
- sort(vp.begin(), vp.end());
- ll int val = 0;
- for(int i=0; i<n; i++)
- val += (vp[i].ff - vp[0].ff + 1);
- vector<ll int> ans(n);
- ans[vp[0].ss] = val;
- for(ll int i=1; i<n; i++)
- {
- val -= (n-i)*(vp[i].ff-vp[i-1].ff);
- val += i*(vp[i].ff-vp[i-1].ff);
- ans[vp[i].ss] = val;
- }
- for(auto e: ans)
- cout<<e<<" ";
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment