답안 #547415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547415 2022-04-10T16:12:39 Z skittles1412 Team Contest (JOI22_team) C++17
100 / 100
1826 ms 190480 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

const int maxn = 150'005;

struct DS1 {
	set<pair<int, int>> s;

	void insert(int x, int y) {
		auto it = s.upper_bound({x, 0});
		if (it != s.begin()) {
			if (prev(it)->second >= y) {
				return;
			}
		}
		while (it != s.end() && y >= it->second) {
			it = s.erase(it);
		}
		s.emplace_hint(it, x, y);
	}

	int query(int x) const {
		auto it = s.lower_bound({x, 0});
		if (it == s.begin()) {
			return -1;
		}
		return (--it)->second;
	}
};

struct DS2 {
	DS1 ds;

	void insert(int x, int y) {
		ds.insert(y, x);
	}

	int query(int y) const {
		return ds.query(y);
	}
};

struct chash {
	uint64_t operator()(uint64_t x) const {
		x ^= x << 11;
		x ^= x >> 9;
		x ^= x >> 7;
		return x;
	}
};

struct Bit1 {
	__gnu_pbds::gp_hash_table<int, int, chash> v;

	void insert(int ind, int x) {
		ind++;
		while (ind <= maxn) {
			v[ind] = max(v[ind], x);
			ind += ind & -ind;
		}
	}

	int query(int ind) const {
		int ans = -1;
		while (ind) {
			auto it = v.find(ind);
			if (it != v.end()) {
				ans = max(ans, it->second);
			}
			ind -= ind & -ind;
		}
		return ans;
	}
};

struct DS3 {
	Bit1 v[maxn + 1];

	void insert(int ind, int y, int val) {
		ind = maxn - ind;
		y = maxn - y;
		ind++;
		while (ind <= maxn) {
			v[ind].insert(y, val);
			ind += ind & -ind;
		}
	}

	int query(int ind, int y) const {
		ind = maxn - ind;
		y = maxn - y;
		int ans = -1;
		while (ind) {
			ans = max(ans, v[ind].query(y));
			ind -= ind & -ind;
		}
		return ans;
	}
};

struct Comp {
	vector<int> comp;

	Comp(int n, array<int, 3> arr[], int ind) : comp(n) {
		for (int i = 0; i < n; i++) {
			comp[i] = arr[i][ind];
		}
		sort(begin(comp), end(comp));
		comp.erase(unique(begin(comp), end(comp)), comp.end());
	}

	int operator[](int ind) const {
		return int(lower_bound(begin(comp), end(comp), ind) - comp.begin());
	}
};

DS1 ds1;
DS2 ds2;
DS3 ds3;

void solve() {
	int n;
	cin >> n;
	array<int, 3> arr[n];
	for (auto& [x, y, z] : arr) {
		cin >> x >> y >> z;
	}
	sort(arr, arr + n);
	Comp xs(n, arr, 1), ys(n, arr, 2);
	int ans = -1;
	for (int i = 0; i < n;) {
		int start = i;
		for (; i < n && arr[start][0] == arr[i][0]; i++) {
			auto& [z, x, y] = arr[i];
			int cur = ds3.query(xs[x], ys[y]);
			if (cur != -1) {
				ans = max(ans, z + cur);
			}
		}
		for (int j = start; j < i; j++) {
			auto& [_, x, y] = arr[j];
			int ly = ds1.query(x);
			if (ly > y) {
				ds3.insert(xs[x], ys[ly], x + ly);
			}
			int rx = ds2.query(y);
			if (rx > x) {
				ds3.insert(xs[rx], ys[y], rx + y);
			}
			ds1.insert(x, y);
			ds2.insert(x, y);
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 31956 KB Output is correct
2 Correct 30 ms 31960 KB Output is correct
3 Correct 28 ms 31956 KB Output is correct
4 Correct 28 ms 31956 KB Output is correct
5 Correct 28 ms 31904 KB Output is correct
6 Correct 27 ms 31956 KB Output is correct
7 Correct 36 ms 31956 KB Output is correct
8 Correct 26 ms 31900 KB Output is correct
9 Correct 27 ms 31984 KB Output is correct
10 Correct 36 ms 31948 KB Output is correct
11 Correct 29 ms 31916 KB Output is correct
12 Correct 27 ms 31956 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 38 ms 32040 KB Output is correct
15 Correct 29 ms 31920 KB Output is correct
16 Correct 28 ms 32020 KB Output is correct
17 Correct 27 ms 32056 KB Output is correct
18 Correct 26 ms 32048 KB Output is correct
19 Correct 31 ms 31944 KB Output is correct
20 Correct 28 ms 31956 KB Output is correct
21 Correct 30 ms 31916 KB Output is correct
22 Correct 28 ms 31980 KB Output is correct
23 Correct 27 ms 31916 KB Output is correct
24 Correct 32 ms 31968 KB Output is correct
25 Correct 29 ms 31956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 31956 KB Output is correct
2 Correct 30 ms 31960 KB Output is correct
3 Correct 28 ms 31956 KB Output is correct
4 Correct 28 ms 31956 KB Output is correct
5 Correct 28 ms 31904 KB Output is correct
6 Correct 27 ms 31956 KB Output is correct
7 Correct 36 ms 31956 KB Output is correct
8 Correct 26 ms 31900 KB Output is correct
9 Correct 27 ms 31984 KB Output is correct
10 Correct 36 ms 31948 KB Output is correct
11 Correct 29 ms 31916 KB Output is correct
12 Correct 27 ms 31956 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 38 ms 32040 KB Output is correct
15 Correct 29 ms 31920 KB Output is correct
16 Correct 28 ms 32020 KB Output is correct
17 Correct 27 ms 32056 KB Output is correct
18 Correct 26 ms 32048 KB Output is correct
19 Correct 31 ms 31944 KB Output is correct
20 Correct 28 ms 31956 KB Output is correct
21 Correct 30 ms 31916 KB Output is correct
22 Correct 28 ms 31980 KB Output is correct
23 Correct 27 ms 31916 KB Output is correct
24 Correct 32 ms 31968 KB Output is correct
25 Correct 29 ms 31956 KB Output is correct
26 Correct 44 ms 33864 KB Output is correct
27 Correct 49 ms 33556 KB Output is correct
28 Correct 44 ms 33056 KB Output is correct
29 Correct 36 ms 32436 KB Output is correct
30 Correct 45 ms 32672 KB Output is correct
31 Correct 46 ms 32600 KB Output is correct
32 Correct 32 ms 32196 KB Output is correct
33 Correct 45 ms 32040 KB Output is correct
34 Correct 31 ms 32452 KB Output is correct
35 Correct 29 ms 31944 KB Output is correct
36 Correct 28 ms 31956 KB Output is correct
37 Correct 36 ms 32148 KB Output is correct
38 Correct 29 ms 32084 KB Output is correct
39 Correct 33 ms 31992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 32024 KB Output is correct
2 Correct 27 ms 31924 KB Output is correct
3 Correct 27 ms 31924 KB Output is correct
4 Correct 27 ms 31956 KB Output is correct
5 Correct 27 ms 31956 KB Output is correct
6 Correct 37 ms 31908 KB Output is correct
7 Correct 39 ms 32004 KB Output is correct
8 Correct 36 ms 31928 KB Output is correct
9 Correct 27 ms 31956 KB Output is correct
10 Correct 29 ms 31956 KB Output is correct
11 Correct 122 ms 34952 KB Output is correct
12 Correct 91 ms 33948 KB Output is correct
13 Correct 115 ms 34464 KB Output is correct
14 Correct 116 ms 34920 KB Output is correct
15 Correct 115 ms 34920 KB Output is correct
16 Correct 125 ms 34892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 32024 KB Output is correct
2 Correct 27 ms 31924 KB Output is correct
3 Correct 27 ms 31924 KB Output is correct
4 Correct 27 ms 31956 KB Output is correct
5 Correct 27 ms 31956 KB Output is correct
6 Correct 37 ms 31908 KB Output is correct
7 Correct 39 ms 32004 KB Output is correct
8 Correct 36 ms 31928 KB Output is correct
9 Correct 27 ms 31956 KB Output is correct
10 Correct 29 ms 31956 KB Output is correct
11 Correct 122 ms 34952 KB Output is correct
12 Correct 91 ms 33948 KB Output is correct
13 Correct 115 ms 34464 KB Output is correct
14 Correct 116 ms 34920 KB Output is correct
15 Correct 115 ms 34920 KB Output is correct
16 Correct 125 ms 34892 KB Output is correct
17 Correct 31 ms 31948 KB Output is correct
18 Correct 29 ms 31924 KB Output is correct
19 Correct 27 ms 31900 KB Output is correct
20 Correct 28 ms 32000 KB Output is correct
21 Correct 27 ms 32044 KB Output is correct
22 Correct 149 ms 34920 KB Output is correct
23 Correct 137 ms 34884 KB Output is correct
24 Correct 104 ms 34064 KB Output is correct
25 Correct 130 ms 34960 KB Output is correct
26 Correct 119 ms 34912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 32024 KB Output is correct
2 Correct 27 ms 31924 KB Output is correct
3 Correct 27 ms 31924 KB Output is correct
4 Correct 27 ms 31956 KB Output is correct
5 Correct 27 ms 31956 KB Output is correct
6 Correct 37 ms 31908 KB Output is correct
7 Correct 39 ms 32004 KB Output is correct
8 Correct 36 ms 31928 KB Output is correct
9 Correct 27 ms 31956 KB Output is correct
10 Correct 29 ms 31956 KB Output is correct
11 Correct 122 ms 34952 KB Output is correct
12 Correct 91 ms 33948 KB Output is correct
13 Correct 115 ms 34464 KB Output is correct
14 Correct 116 ms 34920 KB Output is correct
15 Correct 115 ms 34920 KB Output is correct
16 Correct 125 ms 34892 KB Output is correct
17 Correct 31 ms 31948 KB Output is correct
18 Correct 29 ms 31924 KB Output is correct
19 Correct 27 ms 31900 KB Output is correct
20 Correct 28 ms 32000 KB Output is correct
21 Correct 27 ms 32044 KB Output is correct
22 Correct 149 ms 34920 KB Output is correct
23 Correct 137 ms 34884 KB Output is correct
24 Correct 104 ms 34064 KB Output is correct
25 Correct 130 ms 34960 KB Output is correct
26 Correct 119 ms 34912 KB Output is correct
27 Correct 37 ms 32064 KB Output is correct
28 Correct 29 ms 31960 KB Output is correct
29 Correct 26 ms 31956 KB Output is correct
30 Correct 27 ms 31956 KB Output is correct
31 Correct 41 ms 32220 KB Output is correct
32 Correct 32 ms 31948 KB Output is correct
33 Correct 29 ms 31956 KB Output is correct
34 Correct 205 ms 34948 KB Output is correct
35 Correct 212 ms 35260 KB Output is correct
36 Correct 194 ms 35532 KB Output is correct
37 Correct 172 ms 35620 KB Output is correct
38 Correct 122 ms 34764 KB Output is correct
39 Correct 94 ms 33792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 32024 KB Output is correct
2 Correct 27 ms 31924 KB Output is correct
3 Correct 27 ms 31924 KB Output is correct
4 Correct 27 ms 31956 KB Output is correct
5 Correct 27 ms 31956 KB Output is correct
6 Correct 37 ms 31908 KB Output is correct
7 Correct 39 ms 32004 KB Output is correct
8 Correct 36 ms 31928 KB Output is correct
9 Correct 27 ms 31956 KB Output is correct
10 Correct 29 ms 31956 KB Output is correct
11 Correct 122 ms 34952 KB Output is correct
12 Correct 91 ms 33948 KB Output is correct
13 Correct 115 ms 34464 KB Output is correct
14 Correct 116 ms 34920 KB Output is correct
15 Correct 115 ms 34920 KB Output is correct
16 Correct 125 ms 34892 KB Output is correct
17 Correct 31 ms 31948 KB Output is correct
18 Correct 29 ms 31924 KB Output is correct
19 Correct 27 ms 31900 KB Output is correct
20 Correct 28 ms 32000 KB Output is correct
21 Correct 27 ms 32044 KB Output is correct
22 Correct 149 ms 34920 KB Output is correct
23 Correct 137 ms 34884 KB Output is correct
24 Correct 104 ms 34064 KB Output is correct
25 Correct 130 ms 34960 KB Output is correct
26 Correct 119 ms 34912 KB Output is correct
27 Correct 37 ms 32064 KB Output is correct
28 Correct 29 ms 31960 KB Output is correct
29 Correct 26 ms 31956 KB Output is correct
30 Correct 27 ms 31956 KB Output is correct
31 Correct 41 ms 32220 KB Output is correct
32 Correct 32 ms 31948 KB Output is correct
33 Correct 29 ms 31956 KB Output is correct
34 Correct 205 ms 34948 KB Output is correct
35 Correct 212 ms 35260 KB Output is correct
36 Correct 194 ms 35532 KB Output is correct
37 Correct 172 ms 35620 KB Output is correct
38 Correct 122 ms 34764 KB Output is correct
39 Correct 94 ms 33792 KB Output is correct
40 Correct 35 ms 32604 KB Output is correct
41 Correct 37 ms 32588 KB Output is correct
42 Correct 31 ms 32084 KB Output is correct
43 Correct 32 ms 32148 KB Output is correct
44 Correct 378 ms 36964 KB Output is correct
45 Correct 318 ms 45360 KB Output is correct
46 Correct 321 ms 43864 KB Output is correct
47 Correct 290 ms 45172 KB Output is correct
48 Correct 132 ms 34952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 31956 KB Output is correct
2 Correct 30 ms 31960 KB Output is correct
3 Correct 28 ms 31956 KB Output is correct
4 Correct 28 ms 31956 KB Output is correct
5 Correct 28 ms 31904 KB Output is correct
6 Correct 27 ms 31956 KB Output is correct
7 Correct 36 ms 31956 KB Output is correct
8 Correct 26 ms 31900 KB Output is correct
9 Correct 27 ms 31984 KB Output is correct
10 Correct 36 ms 31948 KB Output is correct
11 Correct 29 ms 31916 KB Output is correct
12 Correct 27 ms 31956 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 38 ms 32040 KB Output is correct
15 Correct 29 ms 31920 KB Output is correct
16 Correct 28 ms 32020 KB Output is correct
17 Correct 27 ms 32056 KB Output is correct
18 Correct 26 ms 32048 KB Output is correct
19 Correct 31 ms 31944 KB Output is correct
20 Correct 28 ms 31956 KB Output is correct
21 Correct 30 ms 31916 KB Output is correct
22 Correct 28 ms 31980 KB Output is correct
23 Correct 27 ms 31916 KB Output is correct
24 Correct 32 ms 31968 KB Output is correct
25 Correct 29 ms 31956 KB Output is correct
26 Correct 44 ms 33864 KB Output is correct
27 Correct 49 ms 33556 KB Output is correct
28 Correct 44 ms 33056 KB Output is correct
29 Correct 36 ms 32436 KB Output is correct
30 Correct 45 ms 32672 KB Output is correct
31 Correct 46 ms 32600 KB Output is correct
32 Correct 32 ms 32196 KB Output is correct
33 Correct 45 ms 32040 KB Output is correct
34 Correct 31 ms 32452 KB Output is correct
35 Correct 29 ms 31944 KB Output is correct
36 Correct 28 ms 31956 KB Output is correct
37 Correct 36 ms 32148 KB Output is correct
38 Correct 29 ms 32084 KB Output is correct
39 Correct 33 ms 31992 KB Output is correct
40 Correct 27 ms 32024 KB Output is correct
41 Correct 27 ms 31924 KB Output is correct
42 Correct 27 ms 31924 KB Output is correct
43 Correct 27 ms 31956 KB Output is correct
44 Correct 27 ms 31956 KB Output is correct
45 Correct 37 ms 31908 KB Output is correct
46 Correct 39 ms 32004 KB Output is correct
47 Correct 36 ms 31928 KB Output is correct
48 Correct 27 ms 31956 KB Output is correct
49 Correct 29 ms 31956 KB Output is correct
50 Correct 122 ms 34952 KB Output is correct
51 Correct 91 ms 33948 KB Output is correct
52 Correct 115 ms 34464 KB Output is correct
53 Correct 116 ms 34920 KB Output is correct
54 Correct 115 ms 34920 KB Output is correct
55 Correct 125 ms 34892 KB Output is correct
56 Correct 31 ms 31948 KB Output is correct
57 Correct 29 ms 31924 KB Output is correct
58 Correct 27 ms 31900 KB Output is correct
59 Correct 28 ms 32000 KB Output is correct
60 Correct 27 ms 32044 KB Output is correct
61 Correct 149 ms 34920 KB Output is correct
62 Correct 137 ms 34884 KB Output is correct
63 Correct 104 ms 34064 KB Output is correct
64 Correct 130 ms 34960 KB Output is correct
65 Correct 119 ms 34912 KB Output is correct
66 Correct 37 ms 32064 KB Output is correct
67 Correct 29 ms 31960 KB Output is correct
68 Correct 26 ms 31956 KB Output is correct
69 Correct 27 ms 31956 KB Output is correct
70 Correct 41 ms 32220 KB Output is correct
71 Correct 32 ms 31948 KB Output is correct
72 Correct 29 ms 31956 KB Output is correct
73 Correct 205 ms 34948 KB Output is correct
74 Correct 212 ms 35260 KB Output is correct
75 Correct 194 ms 35532 KB Output is correct
76 Correct 172 ms 35620 KB Output is correct
77 Correct 122 ms 34764 KB Output is correct
78 Correct 94 ms 33792 KB Output is correct
79 Correct 35 ms 32604 KB Output is correct
80 Correct 37 ms 32588 KB Output is correct
81 Correct 31 ms 32084 KB Output is correct
82 Correct 32 ms 32148 KB Output is correct
83 Correct 378 ms 36964 KB Output is correct
84 Correct 318 ms 45360 KB Output is correct
85 Correct 321 ms 43864 KB Output is correct
86 Correct 290 ms 45172 KB Output is correct
87 Correct 132 ms 34952 KB Output is correct
88 Correct 1826 ms 190480 KB Output is correct
89 Correct 772 ms 82092 KB Output is correct
90 Correct 1102 ms 98496 KB Output is correct
91 Correct 506 ms 65004 KB Output is correct
92 Correct 779 ms 60476 KB Output is correct
93 Correct 737 ms 81780 KB Output is correct
94 Correct 545 ms 63056 KB Output is correct
95 Correct 154 ms 34956 KB Output is correct
96 Correct 239 ms 48932 KB Output is correct
97 Correct 135 ms 35048 KB Output is correct
98 Correct 178 ms 37308 KB Output is correct
99 Correct 194 ms 37196 KB Output is correct