This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int maxn = 1e5+10;
const long long mod = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
int n;
ll soma[maxn];
pii pt[maxn];
bool comp(pii a, pii b) {return a.y < b.y;}
int DistanceSum(int N, int *X, int *Y)
{
n = N;
for (int i = 0; i < n; i++)
pt[i+1] = {X[i], Y[i]};
sort(pt+1, pt+n+1);
for (int i = 1; i <= n; i++)
soma[i] = (soma[i-1]+(ll)pt[i].x)%mod;
ll ans = 0LL;
for (int i = 1; i <= n; i++)
{
ll v = (soma[n]-soma[i]+mod)%mod;
ans = (ans+v)%mod;
ans = (ans-((n-i)*(ll)pt[i].x)%mod+mod)%mod;
v = soma[i-1];
ans = (ans-v+mod)%mod;
ans = (ans+((i-1)*(ll)pt[i].x)%mod)%mod;
}
sort(pt+1, pt+n+1, comp);
for (int i = 1; i <= n; i++)
soma[i] = (soma[i-1]+(ll)pt[i].y)%mod;
for (int i = 1; i <= n; i++)
{
ll v = (soma[n]-soma[i]+mod)%mod;
ans = (ans+v)%mod;
ans = (ans-(((ll)n-(ll)i)*(ll)pt[i].y)%mod+mod)%mod;
v = soma[i-1];
ans = (ans-v+mod)%mod;
ans = (ans+(((ll)i-1LL)*(ll)pt[i].y)%mod)%mod;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |