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 N 100005
using namespace std;
const int mod = 1e9;
long long ans = 0;
int group[N];
vector<int> adj[N];
int sz[N];
int sub[N];
vector<int> v[N];
int n;
void dfs(int v,int par){
sub[v] = sz[v];
for(auto u:adj[v]){
if(u == par)continue;
dfs(u,v);
sub[v] += sub[u];
ans += (long long)sub[u]*(n-sub[u]);
}
}
void solve(){
int cnt = 1;
int bef = 1;
for(int i = 0;i<n;i++){
int tmp = cnt;
sort(v[i].begin(),v[i].end());
for(int j = 0;j<v[i].size();j++){
sz[cnt] = 0;
int r = j-1;
bool last = 0;
while(r + 1< v[i].size() && v[i][j] + (r-j+1) == v[i][r+1]){
r++;
if(last == 0 && bef <= group[v[i][r]]){
adj[group[v[i][r]]].push_back(cnt);
adj[cnt].push_back(group[v[i][r]]);
last = 1;
}
else last = 0;
sz[cnt]++;
group[v[i][r]] = cnt;
}
j = r;
cnt++;
}
bef = tmp;
}
//dfs(1,0);
}
int DistanceSum(int n_, int *x, int *y) {
n = n_;
vector<int> compressx,compressy;
for(int i = 0;i<n;i++){
compressx.push_back(x[i]);
compressy.push_back(y[i]);
}
sort(compressx.begin(),compressx.end());
sort(compressy.begin(),compressy.end());
compressx.resize(unique(compressx.begin(),compressx.end())-compressx.begin());
compressy.resize(unique(compressy.begin(),compressy.end())-compressy.begin());
for(int i = 0;i<n;i++){
x[i] = lower_bound(compressx.begin(),compressx.end(),x[i]) - compressx.begin();
y[i] = lower_bound(compressy.begin(),compressy.end(),y[i]) - compressy.begin();
}
for(int i = 0;i<n;i++){
v[x[i]].push_back(y[i]);
}
solve();
return 0;
for(int i = 0;i<n;i++){
v[i].clear();
adj[i].clear();
group[i] = 0;
}
for(int i = 0;i<n;i++){
v[y[i]].push_back(x[i]);
}
solve();
return ans%mod;
}
Compilation message (stderr)
city.cpp: In function 'void solve()':
city.cpp:27:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int j = 0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
city.cpp:31:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | while(r + 1< v[i].size() && v[i][j] + (r-j+1) == v[i][r+1]){
| ~~~~~~^~~~~~~~~~~~~
# | 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... |