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>
using namespace std;
#define sz(a) ((int)(a).size())
typedef vector<int> vint;
typedef vector<vint> vvint;
#ifndef wambule
// #include ".h"
#else
#endif
const int N = 100005;
long long dr;
vector<int> u[2][N];
int g, w[2], gn, z[2][N];
int G(int x, int y) {
int r = z[g][x];
for(int z : u[g][x]) {
if(z ^ y) r += G(z, x);
}
dr += 1ll * r * (gn - r);
return r;
}
int DistanceSum(int n, int *x, int *y) {
gn = n;
for(int i = 1; i <= n; ++i) {
u[0][i].clear();
u[1][i].clear();
z[0][i] = 0;
z[1][i] = 0;
}
vector<pair<int, int>> v;
for(int i = 0; i < n; ++i) {
v.push_back({x[i], y[i]});
}
g = w[0] = 0;
map<pair<int, int>, int> ma;
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); ++i) {
if(!i || (i && v[i].second > v[i - 1].second + 1) || (i && v[i].first > v[i - 1].first)) ++w[g];
if(int a = ma[{v[i].first - 1, v[i].second}]) {
u[g][a].push_back(w[g]);
u[g][w[g]].push_back(a);
}
ma[{v[i].first, v[i].second}] = w[g];
++z[g][w[g]];
}
for(int i = 0; i < v.size(); ++i) {
swap(v[i].first, v[i].second);
}
g = 1; w[1] = 0;
ma.clear();
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); ++i) {
if(!i || (i && v[i].second > v[i - 1].second + 1) || (i && v[i].first > v[i - 1].first)) ++w[g];
if(int a = ma[{v[i].first - 1, v[i].second}]) {
u[g][a].push_back(w[g]);
u[g][w[g]].push_back(a);
}
ma[{v[i].first, v[i].second}] = w[g];
++z[g][w[g]];
}
G(1, dr = g = 0);
G(g = 1, 0);
return dr;
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}
#endif
Compilation message (stderr)
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
city.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
city.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
# | 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... |