#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tuple<ll, ll, ll> plll;
typedef vector<plll> vplll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<pll>> vvpll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
#define loop(i, s, e) for (ll i = (s); i < (e); ++i)
#define loopr(i, e, s) for (ll i = (e)-1; i >= (s); --i)
#define all(a) a.begin(), a.end()
const ll inf = 1e9;
ll ans = 0;
ll n;
typedef tree<pair<ll,int>, null_type, less<pair<ll,int>>, rb_tree_tag, tree_order_statistics_node_update> ost;
int DistanceSum(int N, int *x, int *y) {
n = N;
ost xi, yi;
loopr(i, n, 0) {
ll bigger = xi.size() - xi.order_of_key(make_pair(x[i] + 1, 0));
ll smaller = xi.order_of_key(make_pair(x[i], 0));
ans = (ans - bigger * x[i] + smaller * x[i] + inf + inf) % inf;
bigger = yi.size() - yi.order_of_key(make_pair(y[i] + 1, 0));
smaller = yi.order_of_key(make_pair(y[i], 0));
ans = (ans - (bigger * y[i]) % inf + (smaller * y[i]) % inf + inf + inf) % inf;
xi.insert(make_pair(x[i], i));
yi.insert(make_pair(y[i], i));
}
xi.clear();
yi.clear();
loop(i, 0, n) {
ll bigger = xi.size() - xi.order_of_key(make_pair(x[i] + 1, 0));
ll smaller = xi.order_of_key(make_pair(x[i], 0));
ans = (ans - bigger * x[i] + smaller * x[i] + inf + inf) % inf;
bigger = yi.size() - yi.order_of_key(make_pair(y[i] + 1, 0));
smaller = yi.order_of_key(make_pair(y[i], 0));
ans = (ans - (bigger * y[i]) % inf + (smaller * y[i]) % inf + inf + inf) % inf;
xi.insert(make_pair(x[i], i));
yi.insert(make_pair(y[i], i));
}
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... |