69242023-12-19 22:31:31111Pac-Mancpp17Wrong answer 0/1001.657s155392 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

void bad() {
	cout << "NO" << '\n';
	exit(0);
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N;
	cin >> N;
	vector<int> X(N), Y(N), Z(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> Y[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> Z[i];
	}
	set<tuple<int, int, int>> s;
	for (int i = 0; i < N; i++) {
		s.insert({X[i], Y[i], Z[i]});
	}
	map<pii, vector<int>> xy, yz, zx;
	for (int i = 0; i < N; i++) {
		xy[{X[i], Y[i]}].push_back(Z[i]);
		yz[{Y[i], Z[i]}].push_back(X[i]);
		zx[{Z[i], X[i]}].push_back(Y[i]);
	}
	for (auto& [p, v] : xy) {
		sort(v.begin(), v.end());
	}
	for (auto& [p, v] : yz) {
		sort(v.begin(), v.end());
	}
	for (auto& [p, v] : zx) {
		sort(v.begin(), v.end());
	}
	// same line
	for (int i = 0; i < N; i++) {
		vector<pair<vector<int>&, int>> a = {
			{xy[{X[i], Y[i]}], Z[i]},
			{yz[{Y[i], Z[i]}], X[i]},
			{zx[{Z[i], X[i]}], Y[i]},
		};
		for (auto [v, x] : a) {
			auto t = lower_bound(v.begin(), v.end(), x);
			if (t != v.begin()) {
				if (*prev(t) != *t - 1) {
					bad();
				}
			}
			if (next(t) != v.end()) {
				if (*next(t) != *t + 1) {
					bad();
				}
			}
		}
	}
	// same plane
	map<int, map<int, pii>> xp, yp, zp;
	for (int i = 0; i < N; i++) {
		xp[X[i]][Y[i]];
		yp[Y[i]][Z[i]];
		zp[Z[i]][X[i]];
	}
	for (auto& [x, m] : xp) {
		pii a = {INT_MAX, INT_MIN};
		for (auto t = m.begin(); t != m.end(); t++) {
			t->second = a;
			a.first = min(a.first, xy[{x, t->first}].front());
			a.second = max(a.second, xy[{x, t->first}].back());
		}
	}
	for (auto& [y, m] : yp) {
		pii a = {INT_MAX, INT_MIN};
		for (auto t = m.begin(); t != m.end(); t++) {
			t->second = a;
			a.first = min(a.first, yz[{y, t->first}].front());
			a.second = max(a.second, yz[{y, t->first}].back());
		}
	}
	for (auto& [z, m] : zp) {
		pii a = {INT_MAX, INT_MIN};
		for (auto t = m.begin(); t != m.end(); t++) {
			t->second = a;
			a.first = min(a.first, zx[{z, t->first}].front());
			a.second = max(a.second, zx[{z, t->first}].back());
		}
	}
	map<int, map<int, pii>> xs, ys, zs;
	for (int i = 0; i < N; i++) {
		xs[X[i]][Y[i]];
		ys[Y[i]][Z[i]];
		zs[Z[i]][X[i]];
	}
	for (auto& [x, m] : xs) {
		pii a = {INT_MAX, INT_MIN};
		for (auto t = m.rbegin(); t != m.rend(); t++) {
			t->second = a;
			a.first = min(a.first, xy[{x, t->first}].front());
			a.second = max(a.second, xy[{x, t->first}].back());
		}
	}
	for (auto& [y, m] : ys) {
		pii a = {INT_MAX, INT_MIN};
		for (auto t = m.rbegin(); t != m.rend(); t++) {
			t->second = a;
			a.first = min(a.first, yz[{y, t->first}].front());
			a.second = max(a.second, yz[{y, t->first}].back());
		}
	}
	for (auto& [z, m] : zs) {
		pii a = {INT_MAX, INT_MIN};
		for (auto t = m.rbegin(); t != m.rend(); t++) {
			t->second = a;
			a.first = min(a.first, zx[{z, t->first}].front());
			a.second = max(a.second, zx[{z, t->first}].back());
		}
	}
	for (int i = 0; i < N; i++) {
		if (xp[X[i]][Y[i]].first < Z[i]) {
			if (!s.count({X[i], Y[i] - 1, Z[i]}) && !s.count({X[i], Y[i], Z[i] - 1})) {
				bad();
			}
		}
		if (xs[X[i]][Y[i]].second > Z[i]) {
			if (!s.count({X[i], Y[i] + 1, Z[i]}) && !s.count({X[i], Y[i], Z[i] + 1})) {
				bad();
			}
		}
		if (yp[Y[i]][Z[i]].first < X[i]) {
			if (!s.count({X[i] - 1, Y[i], Z[i]}) && !s.count({X[i], Y[i], Z[i] - 1})) {
				bad();
			}
		}
		if (ys[Y[i]][Z[i]].second > X[i]) {
			if (!s.count({X[i] + 1, Y[i], Z[i]}) && !s.count({X[i], Y[i], Z[i] + 1})) {
				bad();
			}
		}
		if (zp[Z[i]][X[i]].first < Y[i]) {
			if (!s.count({X[i] - 1, Y[i], Z[i]}) && !s.count({X[i], Y[i] - 1, Z[i]})) {
				bad();
			}
		}
		if (zs[Z[i]][X[i]].second > Y[i]) {
			if (!s.count({X[i] + 1, Y[i], Z[i]}) && !s.count({X[i], Y[i] + 1, Z[i]})) {
				bad();
			}
		}
	}
	cout << "YES" << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2104 KiB
2Accepted3ms2260 KiB
3Wrong answer3ms2704 KiB
subtask20/18
4Accepted3ms2560 KiB
5Accepted3ms2868 KiB
6Accepted3ms2860 KiB
7Accepted3ms3104 KiB
8Accepted3ms2972 KiB
9Accepted3ms3008 KiB
10Accepted3ms3232 KiB
11Accepted3ms3412 KiB
12Wrong answer3ms3232 KiB
13Accepted3ms3224 KiB
subtask30/19
14Accepted14ms7888 KiB
15Accepted4ms3584 KiB
16Accepted9ms5480 KiB
17Accepted10ms5712 KiB
18Accepted34ms5832 KiB
19Accepted32ms5784 KiB
20Wrong answer3ms3876 KiB
21Accepted7ms4832 KiB
22Accepted12ms5824 KiB
23Accepted10ms6120 KiB
24Accepted10ms5864 KiB
25Wrong answer32ms6144 KiB
26Accepted3ms3784 KiB
subtask40/24
27Accepted188ms47192 KiB
28Accepted14ms6780 KiB
29Accepted771ms73324 KiB
30Accepted741ms73196 KiB
31Accepted740ms72932 KiB
32Accepted727ms73372 KiB
33Accepted4ms5036 KiB
34Accepted228ms48084 KiB
35Accepted804ms73060 KiB
36Accepted195ms48040 KiB
37Accepted731ms73076 KiB
38Wrong answer736ms73348 KiB
39Accepted4ms4624 KiB
subtask50/22
40Accepted177ms35760 KiB
41Accepted4ms4436 KiB
42Accepted41ms12936 KiB
43Accepted143ms30668 KiB
44Accepted680ms31444 KiB
45Accepted676ms31304 KiB
46Wrong answer3ms4508 KiB
47Accepted3ms4300 KiB
48Accepted27ms10140 KiB
49Accepted129ms28144 KiB
50Accepted143ms30964 KiB
51Accepted158ms31104 KiB
52Wrong answer686ms31736 KiB
53Accepted3ms4516 KiB
subtask60/17
54Accepted442ms87572 KiB
55Accepted1.657s155392 KiB
56Accepted168ms33220 KiB
57Accepted155ms31416 KiB
58Accepted151ms32024 KiB
59Accepted694ms31736 KiB
60Accepted935ms155376 KiB
61Accepted173ms33720 KiB
62Accepted158ms31660 KiB
63Accepted156ms31532 KiB
64Accepted675ms31740 KiB
65Wrong answer688ms31884 KiB
66Accepted217ms67428 KiB