55372023-07-12 13:59:26111Drónfutárcpp14Accepted 100/100442ms57944 KiB
//#include <windows.h>
//#include <psapi.h>
#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};

vector<Pt> v;

int cmp1(const void* _a, const void* _b) {
	Pt a = v[*(int*)_a];
	Pt b = v[*(int*)_b];
	int ca = b1(a);
	int cb = b1(b);
	if (ca < cb) {
		return -1;
	}
	else if (ca > cb) {
		return 1;
	}
	else {
		return 0;
	}
}

int cmp2(const void* _a, const void* _b) {
	Pt a = v[*(int*)_a];
	Pt b = v[*(int*)_b];
	int ca = b2(a);
	int cb = b2(b);
	if (ca < cb) {
		return -1;
	}
	else if (ca > cb) {
		return 1;
	}
	else {
		return 0;
	}
}

int cmp3(const void* _a, const void* _b) {
	Pt a = v[*(int*)_a];
	Pt b = v[*(int*)_b];
	int ca = b3(a);
	int cb = b3(b);
	if (ca < cb) {
		return -1;
	}
	else if (ca > cb) {
		return 1;
	}
	else {
		return 0;
	}
}

int cmp4(const void* _a, const void* _b) {
	Pt a = v[*(int*)_a];
	Pt b = v[*(int*)_b];
	int ca = b4(a);
	int cb = b4(b);
	if (ca < cb) {
		return -1;
	}
	else if (ca > cb) {
		return 1;
	}
	else {
		return 0;
	}
}

int (* cmpv[])(const void*, const void*) = {cmp1, cmp2, cmp3, cmp4};

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

char* pi = new char[10000000];
char* pi0 = pi;

unsigned int ru() {
	while (!isdigit(*pi)) {
		pi++;
	}
	int r = 0;
	while (isdigit(*pi)) {
		r *= 10;
		r += *pi - '0';
		pi++;
	}
	return r;
}

int main() {
	fread(pi, 10000000, 1, stdin);
//	fread(pi, 10000000, 1, fopen("be2.txt", "r"));
	int N = ru();
	v.resize(N);
	vector<int> w(N);
	vector<int> u(N);
	vector<array<int, 4>> y(N);
	vector<vector<int>> st(N * 4);
	for (int i = 0; i < N; i++) {
		v[i].x = ru();
		v[i].y = ru();
	}
	delete pi0;
	iota(w.begin(), w.end(), 0);
	for (int q = 0; q < 4; q++) {
		qsort(w.data(), w.size(), sizeof(int), cmpv[q]);
		fill(u.begin(), u.end(), -1);
		function<void(int, int, int)> seg = [&](int s, int l, int r) {
			if (l == r) {
				st[s] = {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++) {
			y[j][q] = u[j];
		}
	}
	w.clear();
	u.clear();
	st.clear();
	vector<vector<int>> g(N);
	for (int i = 0; i < N; i++) {
		g[i].reserve(8);
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 4; j++) {
			int k = y[i][j];
			if (k != -1) {
				g[i].push_back(k);
				g[k].push_back(i);
			}
		}
	}
	y.clear();
	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 (int i : g[a.second]) {
			if (!vis[i]) {
				pq.push({dist(v[a.second], v[i]), i});
			}
		}
	}
	cout << ans << endl;
//	PROCESS_MEMORY_COUNTERS_EX pmc;
//	GetProcessMemoryInfo(GetCurrentProcess(), (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc));
//	cout << pmc.PeakPagefileUsage << endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1688 KiB
2Accepted442ms55292 KiB
subtask215/15
3Accepted4ms4016 KiB
4Accepted4ms4220 KiB
5Accepted4ms4440 KiB
6Accepted4ms4664 KiB
7Accepted3ms4340 KiB
subtask315/15
8Accepted4ms4016 KiB
9Accepted4ms4220 KiB
10Accepted4ms4440 KiB
11Accepted4ms4664 KiB
12Accepted3ms4340 KiB
13Accepted4ms4796 KiB
14Accepted4ms5000 KiB
15Accepted4ms5252 KiB
16Accepted4ms5464 KiB
17Accepted4ms5676 KiB
subtask435/35
18Accepted4ms4016 KiB
19Accepted4ms4220 KiB
20Accepted4ms4440 KiB
21Accepted4ms4664 KiB
22Accepted3ms4340 KiB
23Accepted4ms4796 KiB
24Accepted4ms5000 KiB
25Accepted4ms5252 KiB
26Accepted4ms5464 KiB
27Accepted4ms5676 KiB
28Accepted4ms5940 KiB
29Accepted70ms15732 KiB
30Accepted108ms20500 KiB
31Accepted108ms20752 KiB
32Accepted61ms24636 KiB
subtask535/35
33Accepted4ms4016 KiB
34Accepted4ms4220 KiB
35Accepted4ms4440 KiB
36Accepted4ms4664 KiB
37Accepted3ms4340 KiB
38Accepted4ms4796 KiB
39Accepted4ms5000 KiB
40Accepted4ms5252 KiB
41Accepted4ms5464 KiB
42Accepted4ms5676 KiB
43Accepted4ms5940 KiB
44Accepted70ms15732 KiB
45Accepted108ms20500 KiB
46Accepted108ms20752 KiB
47Accepted61ms24636 KiB
48Accepted195ms31696 KiB
49Accepted439ms57820 KiB
50Accepted441ms57856 KiB
51Accepted439ms57944 KiB
52Accepted441ms57936 KiB