Submission #715755

#TimeUsernameProblemLanguageResultExecution timeMemory
715755lukameladzeIdeal city (IOI12_city)C++14
100 / 100
136 ms68324 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second //#define int long long #define pii pair <int, int> #define pb push_back const int N = 3e5 + 5, inf = 1e9, mod = 1e9; int n, x[N], y[N], mnx, mny, nx, ny; long long ans,sz[N]; vector <int> vx[N], vy[N],v[N]; map <int, int> vert[N], vert1[N]; void dfs(int a, int p) { for (int to : v[a]) { if (to == p) continue; dfs(to, a); sz[a] += sz[to]; } ans += sz[a] * (n - sz[a]) % mod; ans %= mod; } int DistanceSum(int N, int *X, int *Y) { n = N; int mnx = inf, mny = inf; for (int i = 1; i <= n; i++) { x[i] = X[i - 1]; y[i] = Y[i - 1]; mnx = min(mnx, x[i]); mny = min(mny, y[i]); } for (int i = 1; i <= n; i++) { x[i] -= mnx; y[i] -= mny; nx = max(nx, x[i]); ny = max(ny, y[i]); } for (int i = 1; i <= n; i++) { vx[x[i]].pb(y[i]); } int cnt = 0; for (int i = 0; i <= nx; i++) { sort(vx[i].begin(), vx[i].end()); for (int j = 0; j < vx[i].size(); j++) { int cy = vx[i][j]; if (j == 0 || cy != vx[i][j - 1] + 1) cnt++; sz[cnt]++; vert[i][cy] = cnt; } } for (int i = 1; i <= nx; i++) { for (int j = 0; j < vx[i].size(); j++) { int cy = vx[i][j]; if (vert[i - 1][cy]) { int a = vert[i - 1][cy]; int b = vert[i][cy]; if (v[a].size() && v[a].back() == b) continue; v[a].pb(b); v[b].pb(a); } } } dfs(1, 0); for (int i = 1; i <= cnt; i++) { v[i].clear(); sz[i] = 0; } for (int i = 1; i <= n; i++) { vy[y[i]].pb(x[i]); } cnt = 0; for (int i = 0; i <= ny; i++) { sort(vy[i].begin(), vy[i].end()); for (int j = 0; j < vy[i].size(); j++) { int cx = vy[i][j]; if (j == 0 || cx != vy[i][j - 1] + 1) cnt++; sz[cnt]++; vert1[cx][i] = cnt; } } for (int i = 1; i <= ny; i++) { for (int j = 0; j < vy[i].size(); j++) { int cx = vy[i][j]; if (vert1[cx][i - 1]) { int a = vert1[cx][i - 1]; int b = vert1[cx][i]; if (v[a].size() && v[a].back() == b) continue; v[a].pb(b); v[b].pb(a); } } } dfs(1, 0); return ans; }

Compilation message (stderr)

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for (int j = 0; j < vx[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~
city.cpp:47:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (int j = 0; j < vx[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~
city.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for (int j = 0; j < vy[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~
city.cpp:74:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for (int j = 0; j < vy[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...