Submission #544593

# Submission time Handle Problem Language Result Execution time Memory
544593 2022-04-02T13:16:22 Z pavement Team Contest (JOI22_team) C++17
100 / 100
446 ms 51212 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, ans, X[150005], Y[150005], Z[150005], S[150005], dX[150005], dY[150005], dZ[150005], mx[150005], _X[150005], _Y[150005], _Z[150005];
ii ft[150005];
iii T[150005];
vector<int> buffer, vX, vY, vZ;
ordered_set<iii> active_points;

int ls(int x) { return x & -x; }

int ft_qry(int p) {
	ii ret = mp(0, 0);
	for (; p; p -= ls(p)) ret = max(ret, ft[p]);
	return ret.second;
}

void ft_upd(int p, int v) {
	for (; p <= vY.size(); p += ls(p)) ft[p] = max(ft[p], mp(Z[v], v));
}

struct node {
	node *left, *right;
	int S, E, val;
	node(int _s, int _e) : S(_s), E(_e), val(-1e9) {
		if (S == E) return;
		int M = (S + E) >> 1;
		left = new node(S, M);
		right = new node(M + 1, E);
	}
	void upd(int p, int v) {
		if (S == E) {
			val = v;
			return;
		}
		int M = (S + E) >> 1;
		if (p <= M) left->upd(p, v);
		else right->upd(p, v);
		val = max(left->val, right->val);
	}
	int qry(int l, int r) {
		if (l > E || r < S) return -1e9;
		if (l <= S && E <= r) return val;
		return max(left->qry(l, r), right->qry(l, r));
	}
} *root;

void remove_point(int x) {
	root->upd(dY[x], -1e9);
}

void add_point(int x) {
	if (mx[dY[x]] >= dZ[S[x]]) return;
	mx[dY[x]] = dZ[S[x]];
	vector<ordered_set<iii>::iterator> to_del;
	// add point (dY[x], dZ[S[x]]) with value Y[x] + Z[S[x]]
	auto it = active_points.upper_bound(mt(dY[x], (int)1e9, (int)1e9));
	if (it != active_points.end() && g1(*it) >= dZ[S[x]]) return;
	while (it != active_points.begin()) {
		--it;
		if (g1(*it) <= dZ[S[x]]) {
			remove_point(g2(*it));
			to_del.pb(it);
		} else break;
	}
	for (auto i : to_del) active_points.erase(i);
	root->upd(dY[x], Y[x] + Z[S[x]]);
	active_points.insert(mt(dY[x], dZ[S[x]], x));
}

void solve() {
	memset(X, 0, sizeof X);
	memset(Y, 0, sizeof Y);
	memset(Z, 0, sizeof Z);
	memset(S, 0, sizeof S);
	memset(dX, 0, sizeof dX);
	memset(dY, 0, sizeof dY);
	memset(dZ, 0, sizeof dZ);
	memset(mx, 0, sizeof mx);
	for (int i = 0; i < 150005; i++) {
		ft[i] = mp(0, 0);
		T[i] = mt(0, 0, 0);
	}
	buffer.clear();
	vX.clear();
	vY.clear();
	vZ.clear();
	active_points.clear();
	for (int i = 1; i <= N; i++) {
		X[i] = _X[i];
		Y[i] = _Y[i];
		Z[i] = _Z[i];
		T[i] = mt(X[i], Y[i], Z[i]);
		vX.pb(X[i]);
		vY.pb(Y[i]);
		vZ.pb(Z[i]);
	}
	sort(vX.begin(), vX.end());
	vX.erase(unique(vX.begin(), vX.end()), vX.end());
	sort(vY.begin(), vY.end());
	vY.erase(unique(vY.begin(), vY.end()), vY.end());
	sort(vZ.begin(), vZ.end());
	vZ.erase(unique(vZ.begin(), vZ.end()), vZ.end());
	sort(T + 1, T + 1 + N);
	for (int i = 1; i <= N; i++) {
		tie(X[i], Y[i], Z[i]) = T[i];
		dX[i] = lower_bound(vX.begin(), vX.end(), X[i]) - vX.begin() + 1;
		dY[i] = lower_bound(vY.begin(), vY.end(), Y[i]) - vY.begin() + 1;
		dZ[i] = lower_bound(vZ.begin(), vZ.end(), Z[i]) - vZ.begin() + 1;
	}
	root = new node(1, N);
	for (int i = 1; i <= N; i++) {
		if (X[i] > X[i - 1]) {
			for (int j : buffer) add_point(j);
			buffer.clear();
		}
		int lo = 0, hi = (int)active_points.size() - 1, lb = -1;
		while (lo <= hi) {
			int mid = (lo + hi) >> 1;
			if (g0(*active_points.find_by_order(mid)) > dY[i]) lb = mid, hi = mid - 1;
			else lo = mid + 1;
		}
		lo = 0, hi = (int)active_points.size() - 1;
		int rb = -1;
		while (lo <= hi) {
			int mid = (lo + hi) >> 1;
			if (g1(*active_points.find_by_order(mid)) > dZ[i]) rb = mid, lo = mid + 1;
			else hi = mid - 1;
		}
		if (lb != -1 && rb != -1)
			ans = max(ans, X[i] + root->qry(g0(*active_points.find_by_order(lb)), g0(*active_points.find_by_order(rb))));
		S[i] = ft_qry(dY[i] - 1);
		ft_upd(dY[i], i);
		if (Z[S[i]] > Z[i]) buffer.pb(i);
	}
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> _X[i] >> _Y[i] >> _Z[i];
	solve();
	for (int i = 1; i <= N; i++) swap(_Y[i], _Z[i]);
	solve();
	cout << (ans == 0 ? -1 : ans) << '\n';
}

Compilation message

team.cpp: In function 'void ft_upd(long long int, long long int)':
team.cpp:44:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (; p <= vY.size(); p += ls(p)) ft[p] = max(ft[p], mp(Z[v], v));
      |         ~~^~~~~~~~~~~~
team.cpp: At global scope:
team.cpp:163:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  163 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15572 KB Output is correct
2 Correct 14 ms 15504 KB Output is correct
3 Correct 8 ms 15576 KB Output is correct
4 Correct 8 ms 15572 KB Output is correct
5 Correct 8 ms 15608 KB Output is correct
6 Correct 8 ms 15572 KB Output is correct
7 Correct 9 ms 15528 KB Output is correct
8 Correct 8 ms 15572 KB Output is correct
9 Correct 8 ms 15572 KB Output is correct
10 Correct 10 ms 15572 KB Output is correct
11 Correct 14 ms 15604 KB Output is correct
12 Correct 9 ms 15572 KB Output is correct
13 Correct 26 ms 15484 KB Output is correct
14 Correct 9 ms 15572 KB Output is correct
15 Correct 33 ms 15648 KB Output is correct
16 Correct 10 ms 15572 KB Output is correct
17 Correct 12 ms 15592 KB Output is correct
18 Correct 13 ms 15572 KB Output is correct
19 Correct 9 ms 15572 KB Output is correct
20 Correct 8 ms 15572 KB Output is correct
21 Correct 9 ms 15572 KB Output is correct
22 Correct 27 ms 15572 KB Output is correct
23 Correct 9 ms 15572 KB Output is correct
24 Correct 9 ms 15572 KB Output is correct
25 Correct 14 ms 15604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15572 KB Output is correct
2 Correct 14 ms 15504 KB Output is correct
3 Correct 8 ms 15576 KB Output is correct
4 Correct 8 ms 15572 KB Output is correct
5 Correct 8 ms 15608 KB Output is correct
6 Correct 8 ms 15572 KB Output is correct
7 Correct 9 ms 15528 KB Output is correct
8 Correct 8 ms 15572 KB Output is correct
9 Correct 8 ms 15572 KB Output is correct
10 Correct 10 ms 15572 KB Output is correct
11 Correct 14 ms 15604 KB Output is correct
12 Correct 9 ms 15572 KB Output is correct
13 Correct 26 ms 15484 KB Output is correct
14 Correct 9 ms 15572 KB Output is correct
15 Correct 33 ms 15648 KB Output is correct
16 Correct 10 ms 15572 KB Output is correct
17 Correct 12 ms 15592 KB Output is correct
18 Correct 13 ms 15572 KB Output is correct
19 Correct 9 ms 15572 KB Output is correct
20 Correct 8 ms 15572 KB Output is correct
21 Correct 9 ms 15572 KB Output is correct
22 Correct 27 ms 15572 KB Output is correct
23 Correct 9 ms 15572 KB Output is correct
24 Correct 9 ms 15572 KB Output is correct
25 Correct 14 ms 15604 KB Output is correct
26 Correct 21 ms 16528 KB Output is correct
27 Correct 16 ms 16436 KB Output is correct
28 Correct 29 ms 16420 KB Output is correct
29 Correct 18 ms 16444 KB Output is correct
30 Correct 14 ms 16212 KB Output is correct
31 Correct 16 ms 16432 KB Output is correct
32 Correct 14 ms 16528 KB Output is correct
33 Correct 13 ms 16484 KB Output is correct
34 Correct 17 ms 16480 KB Output is correct
35 Correct 17 ms 15760 KB Output is correct
36 Correct 12 ms 15780 KB Output is correct
37 Correct 13 ms 16480 KB Output is correct
38 Correct 15 ms 16468 KB Output is correct
39 Correct 10 ms 16084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15608 KB Output is correct
2 Correct 14 ms 15572 KB Output is correct
3 Correct 15 ms 15572 KB Output is correct
4 Correct 13 ms 15572 KB Output is correct
5 Correct 10 ms 15608 KB Output is correct
6 Correct 10 ms 15484 KB Output is correct
7 Correct 11 ms 15584 KB Output is correct
8 Correct 9 ms 15572 KB Output is correct
9 Correct 17 ms 15572 KB Output is correct
10 Correct 11 ms 15604 KB Output is correct
11 Correct 180 ms 50952 KB Output is correct
12 Correct 83 ms 39128 KB Output is correct
13 Correct 88 ms 44580 KB Output is correct
14 Correct 131 ms 51032 KB Output is correct
15 Correct 114 ms 51212 KB Output is correct
16 Correct 103 ms 50820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15608 KB Output is correct
2 Correct 14 ms 15572 KB Output is correct
3 Correct 15 ms 15572 KB Output is correct
4 Correct 13 ms 15572 KB Output is correct
5 Correct 10 ms 15608 KB Output is correct
6 Correct 10 ms 15484 KB Output is correct
7 Correct 11 ms 15584 KB Output is correct
8 Correct 9 ms 15572 KB Output is correct
9 Correct 17 ms 15572 KB Output is correct
10 Correct 11 ms 15604 KB Output is correct
11 Correct 180 ms 50952 KB Output is correct
12 Correct 83 ms 39128 KB Output is correct
13 Correct 88 ms 44580 KB Output is correct
14 Correct 131 ms 51032 KB Output is correct
15 Correct 114 ms 51212 KB Output is correct
16 Correct 103 ms 50820 KB Output is correct
17 Correct 8 ms 15608 KB Output is correct
18 Correct 8 ms 15564 KB Output is correct
19 Correct 23 ms 15592 KB Output is correct
20 Correct 9 ms 15572 KB Output is correct
21 Correct 16 ms 16084 KB Output is correct
22 Correct 167 ms 50804 KB Output is correct
23 Correct 177 ms 50024 KB Output is correct
24 Correct 135 ms 41100 KB Output is correct
25 Correct 147 ms 50880 KB Output is correct
26 Correct 177 ms 51104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15608 KB Output is correct
2 Correct 14 ms 15572 KB Output is correct
3 Correct 15 ms 15572 KB Output is correct
4 Correct 13 ms 15572 KB Output is correct
5 Correct 10 ms 15608 KB Output is correct
6 Correct 10 ms 15484 KB Output is correct
7 Correct 11 ms 15584 KB Output is correct
8 Correct 9 ms 15572 KB Output is correct
9 Correct 17 ms 15572 KB Output is correct
10 Correct 11 ms 15604 KB Output is correct
11 Correct 180 ms 50952 KB Output is correct
12 Correct 83 ms 39128 KB Output is correct
13 Correct 88 ms 44580 KB Output is correct
14 Correct 131 ms 51032 KB Output is correct
15 Correct 114 ms 51212 KB Output is correct
16 Correct 103 ms 50820 KB Output is correct
17 Correct 8 ms 15608 KB Output is correct
18 Correct 8 ms 15564 KB Output is correct
19 Correct 23 ms 15592 KB Output is correct
20 Correct 9 ms 15572 KB Output is correct
21 Correct 16 ms 16084 KB Output is correct
22 Correct 167 ms 50804 KB Output is correct
23 Correct 177 ms 50024 KB Output is correct
24 Correct 135 ms 41100 KB Output is correct
25 Correct 147 ms 50880 KB Output is correct
26 Correct 177 ms 51104 KB Output is correct
27 Correct 9 ms 15676 KB Output is correct
28 Correct 11 ms 15572 KB Output is correct
29 Correct 40 ms 15648 KB Output is correct
30 Correct 18 ms 15572 KB Output is correct
31 Correct 23 ms 16468 KB Output is correct
32 Correct 12 ms 15828 KB Output is correct
33 Correct 14 ms 15740 KB Output is correct
34 Correct 228 ms 49076 KB Output is correct
35 Correct 189 ms 47448 KB Output is correct
36 Correct 258 ms 50776 KB Output is correct
37 Correct 193 ms 50500 KB Output is correct
38 Correct 124 ms 50248 KB Output is correct
39 Correct 81 ms 37432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15608 KB Output is correct
2 Correct 14 ms 15572 KB Output is correct
3 Correct 15 ms 15572 KB Output is correct
4 Correct 13 ms 15572 KB Output is correct
5 Correct 10 ms 15608 KB Output is correct
6 Correct 10 ms 15484 KB Output is correct
7 Correct 11 ms 15584 KB Output is correct
8 Correct 9 ms 15572 KB Output is correct
9 Correct 17 ms 15572 KB Output is correct
10 Correct 11 ms 15604 KB Output is correct
11 Correct 180 ms 50952 KB Output is correct
12 Correct 83 ms 39128 KB Output is correct
13 Correct 88 ms 44580 KB Output is correct
14 Correct 131 ms 51032 KB Output is correct
15 Correct 114 ms 51212 KB Output is correct
16 Correct 103 ms 50820 KB Output is correct
17 Correct 8 ms 15608 KB Output is correct
18 Correct 8 ms 15564 KB Output is correct
19 Correct 23 ms 15592 KB Output is correct
20 Correct 9 ms 15572 KB Output is correct
21 Correct 16 ms 16084 KB Output is correct
22 Correct 167 ms 50804 KB Output is correct
23 Correct 177 ms 50024 KB Output is correct
24 Correct 135 ms 41100 KB Output is correct
25 Correct 147 ms 50880 KB Output is correct
26 Correct 177 ms 51104 KB Output is correct
27 Correct 9 ms 15676 KB Output is correct
28 Correct 11 ms 15572 KB Output is correct
29 Correct 40 ms 15648 KB Output is correct
30 Correct 18 ms 15572 KB Output is correct
31 Correct 23 ms 16468 KB Output is correct
32 Correct 12 ms 15828 KB Output is correct
33 Correct 14 ms 15740 KB Output is correct
34 Correct 228 ms 49076 KB Output is correct
35 Correct 189 ms 47448 KB Output is correct
36 Correct 258 ms 50776 KB Output is correct
37 Correct 193 ms 50500 KB Output is correct
38 Correct 124 ms 50248 KB Output is correct
39 Correct 81 ms 37432 KB Output is correct
40 Correct 14 ms 16212 KB Output is correct
41 Correct 26 ms 16496 KB Output is correct
42 Correct 13 ms 16468 KB Output is correct
43 Correct 15 ms 16424 KB Output is correct
44 Correct 278 ms 50812 KB Output is correct
45 Correct 273 ms 50812 KB Output is correct
46 Correct 335 ms 50808 KB Output is correct
47 Correct 283 ms 50800 KB Output is correct
48 Correct 148 ms 51112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15572 KB Output is correct
2 Correct 14 ms 15504 KB Output is correct
3 Correct 8 ms 15576 KB Output is correct
4 Correct 8 ms 15572 KB Output is correct
5 Correct 8 ms 15608 KB Output is correct
6 Correct 8 ms 15572 KB Output is correct
7 Correct 9 ms 15528 KB Output is correct
8 Correct 8 ms 15572 KB Output is correct
9 Correct 8 ms 15572 KB Output is correct
10 Correct 10 ms 15572 KB Output is correct
11 Correct 14 ms 15604 KB Output is correct
12 Correct 9 ms 15572 KB Output is correct
13 Correct 26 ms 15484 KB Output is correct
14 Correct 9 ms 15572 KB Output is correct
15 Correct 33 ms 15648 KB Output is correct
16 Correct 10 ms 15572 KB Output is correct
17 Correct 12 ms 15592 KB Output is correct
18 Correct 13 ms 15572 KB Output is correct
19 Correct 9 ms 15572 KB Output is correct
20 Correct 8 ms 15572 KB Output is correct
21 Correct 9 ms 15572 KB Output is correct
22 Correct 27 ms 15572 KB Output is correct
23 Correct 9 ms 15572 KB Output is correct
24 Correct 9 ms 15572 KB Output is correct
25 Correct 14 ms 15604 KB Output is correct
26 Correct 21 ms 16528 KB Output is correct
27 Correct 16 ms 16436 KB Output is correct
28 Correct 29 ms 16420 KB Output is correct
29 Correct 18 ms 16444 KB Output is correct
30 Correct 14 ms 16212 KB Output is correct
31 Correct 16 ms 16432 KB Output is correct
32 Correct 14 ms 16528 KB Output is correct
33 Correct 13 ms 16484 KB Output is correct
34 Correct 17 ms 16480 KB Output is correct
35 Correct 17 ms 15760 KB Output is correct
36 Correct 12 ms 15780 KB Output is correct
37 Correct 13 ms 16480 KB Output is correct
38 Correct 15 ms 16468 KB Output is correct
39 Correct 10 ms 16084 KB Output is correct
40 Correct 9 ms 15608 KB Output is correct
41 Correct 14 ms 15572 KB Output is correct
42 Correct 15 ms 15572 KB Output is correct
43 Correct 13 ms 15572 KB Output is correct
44 Correct 10 ms 15608 KB Output is correct
45 Correct 10 ms 15484 KB Output is correct
46 Correct 11 ms 15584 KB Output is correct
47 Correct 9 ms 15572 KB Output is correct
48 Correct 17 ms 15572 KB Output is correct
49 Correct 11 ms 15604 KB Output is correct
50 Correct 180 ms 50952 KB Output is correct
51 Correct 83 ms 39128 KB Output is correct
52 Correct 88 ms 44580 KB Output is correct
53 Correct 131 ms 51032 KB Output is correct
54 Correct 114 ms 51212 KB Output is correct
55 Correct 103 ms 50820 KB Output is correct
56 Correct 8 ms 15608 KB Output is correct
57 Correct 8 ms 15564 KB Output is correct
58 Correct 23 ms 15592 KB Output is correct
59 Correct 9 ms 15572 KB Output is correct
60 Correct 16 ms 16084 KB Output is correct
61 Correct 167 ms 50804 KB Output is correct
62 Correct 177 ms 50024 KB Output is correct
63 Correct 135 ms 41100 KB Output is correct
64 Correct 147 ms 50880 KB Output is correct
65 Correct 177 ms 51104 KB Output is correct
66 Correct 9 ms 15676 KB Output is correct
67 Correct 11 ms 15572 KB Output is correct
68 Correct 40 ms 15648 KB Output is correct
69 Correct 18 ms 15572 KB Output is correct
70 Correct 23 ms 16468 KB Output is correct
71 Correct 12 ms 15828 KB Output is correct
72 Correct 14 ms 15740 KB Output is correct
73 Correct 228 ms 49076 KB Output is correct
74 Correct 189 ms 47448 KB Output is correct
75 Correct 258 ms 50776 KB Output is correct
76 Correct 193 ms 50500 KB Output is correct
77 Correct 124 ms 50248 KB Output is correct
78 Correct 81 ms 37432 KB Output is correct
79 Correct 14 ms 16212 KB Output is correct
80 Correct 26 ms 16496 KB Output is correct
81 Correct 13 ms 16468 KB Output is correct
82 Correct 15 ms 16424 KB Output is correct
83 Correct 278 ms 50812 KB Output is correct
84 Correct 273 ms 50812 KB Output is correct
85 Correct 335 ms 50808 KB Output is correct
86 Correct 283 ms 50800 KB Output is correct
87 Correct 148 ms 51112 KB Output is correct
88 Correct 429 ms 50812 KB Output is correct
89 Correct 386 ms 50800 KB Output is correct
90 Correct 446 ms 50808 KB Output is correct
91 Correct 368 ms 50812 KB Output is correct
92 Correct 324 ms 50812 KB Output is correct
93 Correct 372 ms 50812 KB Output is correct
94 Correct 346 ms 50808 KB Output is correct
95 Correct 183 ms 51068 KB Output is correct
96 Correct 266 ms 50816 KB Output is correct
97 Correct 118 ms 50780 KB Output is correct
98 Correct 214 ms 50812 KB Output is correct
99 Correct 245 ms 50816 KB Output is correct