55352023-07-12 12:40:53111Drónfutárcpp14Runtime error 65/100458ms66432 KiB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>

#define LI (s * 2 + 1)
#define RI (s * 2 + 2)
#define LST (l)
#define LEN ((l + r) / 2)
#define RST ((l + r) / 2 + 1)
#define REN (r)
#define ASZ (r - l + 1)
#define LSZ (LEN - LST + 1)
#define RSZ (REN - RST + 1)

struct Pt { int x, y; };

int b1(Pt p) { return + p.y; 	   }
int b2(Pt p) { return + p.y - p.x; }
int b3(Pt p) { return - p.x; 	   }
int b4(Pt p) { return - p.x - p.y; }

int c1(Pt p) { return + p.x - p.y; }
int c2(Pt p) { return + p.x; 	   }
int c3(Pt p) { return + p.x + p.y; }
int c4(Pt p) { return + p.y; 	   }

int d1(Pt p) { return + p.x + p.y; }
int d2(Pt p) { return + p.x + p.y; }
int d3(Pt p) { return - p.x + p.y; }
int d4(Pt p) { return - p.x + p.y; }

int (* bv[])(Pt p) = {b1, b2, b3, b4};
int (* cv[])(Pt p) = {c1, c2, c3, c4};
int (* dv[])(Pt p) = {d1, d2, d3, d4};

int dist(Pt a, Pt b) { return abs(a.x - b.x) + abs(a.y - b.y); }

int main() {
//	ifstream fin("be2.txt");
//	cin.rdbuf(fin.rdbuf());
	int N;
	cin >> N;
	vector<Pt> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i].x >> v[i].y;
	}
	vector<vector<pair<int, int>>> g(N);
	vector<int> w(N);
	iota(w.begin(), w.end(), 0);
	for (int q = 0; q < 4; q++) {
		sort(w.begin(), w.end(), [&](auto a, auto b) { return bv[q](v[a]) < bv[q](v[b]); });
		vector<int> u(N, -1);
		vector<vector<int>> st(N * 4);
		function<void(int, int, int)> seg = [&](int s, int l, int r) {
			if (l == r) {
				st[s].push_back(w[l]);
				return;
			}
			seg(LI, LST, LEN);
			seg(RI, RST, REN);
			st[s].resize(ASZ);
			int i = 0, j = 0, k = 0, m = -1;
			while (j < LSZ && k < RSZ) {
				int aj = st[LI][j];
				int ak = st[RI][k];
				if (cv[q](v[aj]) > cv[q](v[ak])) {
					if (m != -1 && (u[aj] == -1 || dv[q](v[m]) < dv[q](v[u[aj]]))) {
						u[aj] = m;
					}
					st[s][i] = aj;
					j++;
				}
				else {
					if (m == -1 || dv[q](v[ak]) < dv[q](v[m])) {
						m = ak;
					}
					st[s][i] = ak;
					k++;
				}
				i++;
			}
			while (j < LSZ) {
				int aj = st[LI][j];
				if (m != -1 && (u[aj] == -1 || dv[q](v[m]) < dv[q](v[u[aj]]))) {
					u[aj] = m;
				}
				st[s][i] = aj;
				j++;
				i++;
			}
			while (k < RSZ) {
				st[s][i] = st[RI][k];
				k++;
				i++;
			}
		};
		seg(0, 0, N - 1);
		for (int j = 0; j < N; j++) {
			int k = u[j];
			if (k != -1) {
				g[j].push_back({k, dist(v[j], v[k])});
				g[k].push_back({j, dist(v[j], v[k])});
			}
		}
	}
	int ans = 0;
	vector<bool> vis(N);
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	pq.push({0, 0});
	while (!pq.empty()) {
        pii a = pq.top();
        pq.pop();
        if (vis[a.second]) {
            continue;
        }
        vis[a.second] = true;
		ans = max(ans, a.first);
        for (auto p : g[a.second]) {
            if (!vis[p.first]) {
                pq.push({p.second, p.first});
            }
        }
    }
    cout << ans << endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1880 KiB
2Runtime error458ms66432 KiB
subtask215/15
3Accepted6ms3028 KiB
4Accepted6ms3012 KiB
5Accepted7ms3276 KiB
6Accepted6ms3572 KiB
7Accepted4ms3252 KiB
subtask315/15
8Accepted6ms3028 KiB
9Accepted6ms3012 KiB
10Accepted7ms3276 KiB
11Accepted6ms3572 KiB
12Accepted4ms3252 KiB
13Accepted4ms3620 KiB
14Accepted7ms4084 KiB
15Accepted7ms4268 KiB
16Accepted7ms4560 KiB
17Accepted7ms4800 KiB
subtask435/35
18Accepted6ms3028 KiB
19Accepted6ms3012 KiB
20Accepted7ms3276 KiB
21Accepted6ms3572 KiB
22Accepted4ms3252 KiB
23Accepted4ms3620 KiB
24Accepted7ms4084 KiB
25Accepted7ms4268 KiB
26Accepted7ms4560 KiB
27Accepted7ms4800 KiB
28Accepted7ms4708 KiB
29Accepted108ms18604 KiB
30Accepted168ms26596 KiB
31Accepted168ms26768 KiB
32Accepted136ms30412 KiB
subtask50/35
33Accepted6ms3028 KiB
34Accepted6ms3012 KiB
35Accepted7ms3276 KiB
36Accepted6ms3572 KiB
37Accepted4ms3252 KiB
38Accepted4ms3620 KiB
39Accepted7ms4084 KiB
40Accepted7ms4268 KiB
41Accepted7ms4560 KiB
42Accepted7ms4800 KiB
43Accepted7ms4708 KiB
44Accepted108ms18604 KiB
45Accepted168ms26596 KiB
46Accepted168ms26768 KiB
47Accepted136ms30412 KiB
48Accepted317ms42944 KiB
49Runtime error340ms64412 KiB
50Runtime error314ms64176 KiB
51Runtime error333ms64156 KiB
52Runtime error328ms64124 KiB