Submission #566187

# Submission time Handle Problem Language Result Execution time Memory
566187 2022-05-22T04:08:17 Z 8e7 Team Contest (JOI22_team) C++17
100 / 100
311 ms 25820 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 150005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 1<<30;
struct segtree{
	pii seg[4 * maxn];
	int z[4 * maxn], minz[maxn], type[4 * maxn];
	int tag[4 * maxn];
	
	void push(int cur, int l, int r) {
		if (!tag[cur]) return;
		z[cur] = tag[cur];
		if (type[cur]) seg[cur].ff = z[cur];
		if (r - l > 1) {
			tag[cur*2] = tag[cur];
			tag[cur*2+1] = tag[cur];
		}
		tag[cur] = 0;
	}
	void pull(int cur, int l, int r) {
		int mid = (l + r) / 2;
		push(cur*2, l, mid), push(cur*2+1, mid, r);	
		seg[cur] = max(seg[cur*2], seg[cur*2+1]);	
		z[cur] = max(z[cur*2], z[cur*2+1]);
		type[cur] = type[cur*2] | type[cur*2+1];
	}
	void init(int cur, int l, int r) {
		if (r <= l) return;
		if (r - l == 1) {
			seg[cur] = {0, l};
			minz[l] = inf;
			return;
		}
		int m = (l + r) / 2;
		init(cur*2, l, m), init(cur*2+1, m, r);
		pull(cur, l, r);
	}
	void modify(int cur, int l, int r, int ql, int qr, int val) {
		if (r <= l || ql >= r || qr <= l) return;	
		push(cur, l, r);
		if (ql <= l && qr >= r) {
			tag[cur] = val;	
			return;
		}
		int m = (l + r) / 2;
		modify(cur*2, l, m, ql, qr, val);
		modify(cur*2+1, m, r, ql, qr, val);
		pull(cur, l, r);
	}
	void ch(int cur, int l, int r, int ind) {
		if (r <= l) return;	
		push(cur, l, r);
		if (r - l == 1) {
			if (z[cur] > minz[l]) {
				seg[cur].ff = z[cur];
				type[cur] = 1;
			}
			return;
		}
		int m = (l + r) / 2;
		if (ind < m) ch(cur*2, l, m, ind);
		else ch(cur*2+1, m, r, ind);
		pull(cur, l, r);
	}
	int search(int cur, int l, int r, int v) { //smallest index with z[x] >= v
		if (r <= l) return 0;	
		push(cur, l, r);
		if (r - l == 1) {
			if (z[cur] < v) return l+1;
			else return l;
		}
		int m = (l + r) / 2;
		if (z[cur*2] >= v) return search(cur*2, l, m, v);
		else return search(cur*2+1, m, r, v);
	}
	pii query(int cur, int l, int r, int ql, int qr) {
		if (r <= l || ql >= r || qr <= l) return {-1, 0};
		push(cur, l, r);
		if (ql <= l && qr >= r) return seg[cur];
		int m = (l + r) / 2;
		return max(query(cur*2, l, m, ql, qr), query(cur*2+1, m, r, ql, qr));
	}
} tr;
struct obj{
	int x, y, z;
	obj(){x = y = z = 0;}
	obj(int a, int b, int c){x = a, y = b, z = c;}
} a[maxn];
vector<int> xv, yv;
vector<int> ev[maxn];
int main() {
	io
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i].x >> a[i].y >> a[i].z;
		xv.push_back(a[i].x);
		yv.push_back(a[i].y);
	}
	sort(xv.begin(), xv.end());
	sort(yv.begin(), yv.end());
	xv.resize(int(unique(xv.begin(), xv.end()) - xv.begin()));
	yv.resize(int(unique(yv.begin(), yv.end()) - yv.begin()));
	for (int i = 0;i < n;i++) {
		a[i].x = lower_bound(xv.begin(), xv.end(), a[i].x) - xv.begin();
		a[i].y = lower_bound(yv.begin(), yv.end(), a[i].y) - yv.begin();
		ev[a[i].x].push_back(i);
	}
	int ans = -1;
	int siz = yv.size();
	tr.init(1, 0, siz);
	for (int it = 0;it < n;it++) {
		for (int i:ev[it]) {
			pii best = tr.query(1, 0, siz, a[i].y+1, siz);	
			if (best.ff != -1 && best.ff > a[i].z) {
				ans = max(ans, xv[a[i].x] + yv[best.ss] + best.ff);
			}
		}
		for (int i:ev[it]) {
			int z = a[i].z;
			int rig = tr.search(1, 0, siz, z);
			tr.modify(1, 0, siz, a[i].y + 1, rig, z);
			tr.minz[a[i].y] = min(tr.minz[a[i].y], z);
			tr.ch(1, 0, siz, a[i].y); 
			tr.ch(1, 0, siz, rig-1);
		}
	}
	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10324 KB Output is correct
2 Correct 5 ms 10324 KB Output is correct
3 Correct 7 ms 10244 KB Output is correct
4 Correct 7 ms 10324 KB Output is correct
5 Correct 5 ms 10324 KB Output is correct
6 Correct 5 ms 10324 KB Output is correct
7 Correct 5 ms 10324 KB Output is correct
8 Correct 5 ms 10324 KB Output is correct
9 Correct 5 ms 10196 KB Output is correct
10 Correct 5 ms 10324 KB Output is correct
11 Correct 5 ms 10264 KB Output is correct
12 Correct 5 ms 10324 KB Output is correct
13 Correct 5 ms 10304 KB Output is correct
14 Correct 5 ms 10324 KB Output is correct
15 Correct 5 ms 10324 KB Output is correct
16 Correct 6 ms 10324 KB Output is correct
17 Correct 8 ms 10320 KB Output is correct
18 Correct 5 ms 10324 KB Output is correct
19 Correct 6 ms 10304 KB Output is correct
20 Correct 6 ms 10312 KB Output is correct
21 Correct 5 ms 10324 KB Output is correct
22 Correct 5 ms 10324 KB Output is correct
23 Correct 5 ms 10324 KB Output is correct
24 Correct 6 ms 10324 KB Output is correct
25 Correct 5 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10324 KB Output is correct
2 Correct 5 ms 10324 KB Output is correct
3 Correct 7 ms 10244 KB Output is correct
4 Correct 7 ms 10324 KB Output is correct
5 Correct 5 ms 10324 KB Output is correct
6 Correct 5 ms 10324 KB Output is correct
7 Correct 5 ms 10324 KB Output is correct
8 Correct 5 ms 10324 KB Output is correct
9 Correct 5 ms 10196 KB Output is correct
10 Correct 5 ms 10324 KB Output is correct
11 Correct 5 ms 10264 KB Output is correct
12 Correct 5 ms 10324 KB Output is correct
13 Correct 5 ms 10304 KB Output is correct
14 Correct 5 ms 10324 KB Output is correct
15 Correct 5 ms 10324 KB Output is correct
16 Correct 6 ms 10324 KB Output is correct
17 Correct 8 ms 10320 KB Output is correct
18 Correct 5 ms 10324 KB Output is correct
19 Correct 6 ms 10304 KB Output is correct
20 Correct 6 ms 10312 KB Output is correct
21 Correct 5 ms 10324 KB Output is correct
22 Correct 5 ms 10324 KB Output is correct
23 Correct 5 ms 10324 KB Output is correct
24 Correct 6 ms 10324 KB Output is correct
25 Correct 5 ms 10324 KB Output is correct
26 Correct 10 ms 10580 KB Output is correct
27 Correct 11 ms 10572 KB Output is correct
28 Correct 11 ms 10536 KB Output is correct
29 Correct 11 ms 10424 KB Output is correct
30 Correct 9 ms 10448 KB Output is correct
31 Correct 8 ms 10452 KB Output is correct
32 Correct 8 ms 10320 KB Output is correct
33 Correct 10 ms 10452 KB Output is correct
34 Correct 9 ms 10564 KB Output is correct
35 Correct 7 ms 10324 KB Output is correct
36 Correct 6 ms 10324 KB Output is correct
37 Correct 10 ms 10452 KB Output is correct
38 Correct 10 ms 10452 KB Output is correct
39 Correct 6 ms 10280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10324 KB Output is correct
2 Correct 4 ms 10324 KB Output is correct
3 Correct 5 ms 10196 KB Output is correct
4 Correct 6 ms 10220 KB Output is correct
5 Correct 5 ms 10324 KB Output is correct
6 Correct 6 ms 10324 KB Output is correct
7 Correct 5 ms 10268 KB Output is correct
8 Correct 5 ms 10260 KB Output is correct
9 Correct 5 ms 10196 KB Output is correct
10 Correct 5 ms 10324 KB Output is correct
11 Correct 51 ms 12308 KB Output is correct
12 Correct 36 ms 11704 KB Output is correct
13 Correct 40 ms 12136 KB Output is correct
14 Correct 48 ms 12736 KB Output is correct
15 Correct 47 ms 12596 KB Output is correct
16 Correct 35 ms 13112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10324 KB Output is correct
2 Correct 4 ms 10324 KB Output is correct
3 Correct 5 ms 10196 KB Output is correct
4 Correct 6 ms 10220 KB Output is correct
5 Correct 5 ms 10324 KB Output is correct
6 Correct 6 ms 10324 KB Output is correct
7 Correct 5 ms 10268 KB Output is correct
8 Correct 5 ms 10260 KB Output is correct
9 Correct 5 ms 10196 KB Output is correct
10 Correct 5 ms 10324 KB Output is correct
11 Correct 51 ms 12308 KB Output is correct
12 Correct 36 ms 11704 KB Output is correct
13 Correct 40 ms 12136 KB Output is correct
14 Correct 48 ms 12736 KB Output is correct
15 Correct 47 ms 12596 KB Output is correct
16 Correct 35 ms 13112 KB Output is correct
17 Correct 6 ms 10196 KB Output is correct
18 Correct 6 ms 10324 KB Output is correct
19 Correct 6 ms 10196 KB Output is correct
20 Correct 6 ms 10324 KB Output is correct
21 Correct 8 ms 10360 KB Output is correct
22 Correct 74 ms 12280 KB Output is correct
23 Correct 67 ms 12276 KB Output is correct
24 Correct 60 ms 11836 KB Output is correct
25 Correct 87 ms 12548 KB Output is correct
26 Correct 55 ms 12592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10324 KB Output is correct
2 Correct 4 ms 10324 KB Output is correct
3 Correct 5 ms 10196 KB Output is correct
4 Correct 6 ms 10220 KB Output is correct
5 Correct 5 ms 10324 KB Output is correct
6 Correct 6 ms 10324 KB Output is correct
7 Correct 5 ms 10268 KB Output is correct
8 Correct 5 ms 10260 KB Output is correct
9 Correct 5 ms 10196 KB Output is correct
10 Correct 5 ms 10324 KB Output is correct
11 Correct 51 ms 12308 KB Output is correct
12 Correct 36 ms 11704 KB Output is correct
13 Correct 40 ms 12136 KB Output is correct
14 Correct 48 ms 12736 KB Output is correct
15 Correct 47 ms 12596 KB Output is correct
16 Correct 35 ms 13112 KB Output is correct
17 Correct 6 ms 10196 KB Output is correct
18 Correct 6 ms 10324 KB Output is correct
19 Correct 6 ms 10196 KB Output is correct
20 Correct 6 ms 10324 KB Output is correct
21 Correct 8 ms 10360 KB Output is correct
22 Correct 74 ms 12280 KB Output is correct
23 Correct 67 ms 12276 KB Output is correct
24 Correct 60 ms 11836 KB Output is correct
25 Correct 87 ms 12548 KB Output is correct
26 Correct 55 ms 12592 KB Output is correct
27 Correct 5 ms 10324 KB Output is correct
28 Correct 6 ms 10324 KB Output is correct
29 Correct 6 ms 10324 KB Output is correct
30 Correct 6 ms 10324 KB Output is correct
31 Correct 9 ms 10440 KB Output is correct
32 Correct 7 ms 10284 KB Output is correct
33 Correct 6 ms 10324 KB Output is correct
34 Correct 99 ms 12308 KB Output is correct
35 Correct 128 ms 12600 KB Output is correct
36 Correct 124 ms 12652 KB Output is correct
37 Correct 111 ms 12472 KB Output is correct
38 Correct 68 ms 12536 KB Output is correct
39 Correct 44 ms 11876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10324 KB Output is correct
2 Correct 4 ms 10324 KB Output is correct
3 Correct 5 ms 10196 KB Output is correct
4 Correct 6 ms 10220 KB Output is correct
5 Correct 5 ms 10324 KB Output is correct
6 Correct 6 ms 10324 KB Output is correct
7 Correct 5 ms 10268 KB Output is correct
8 Correct 5 ms 10260 KB Output is correct
9 Correct 5 ms 10196 KB Output is correct
10 Correct 5 ms 10324 KB Output is correct
11 Correct 51 ms 12308 KB Output is correct
12 Correct 36 ms 11704 KB Output is correct
13 Correct 40 ms 12136 KB Output is correct
14 Correct 48 ms 12736 KB Output is correct
15 Correct 47 ms 12596 KB Output is correct
16 Correct 35 ms 13112 KB Output is correct
17 Correct 6 ms 10196 KB Output is correct
18 Correct 6 ms 10324 KB Output is correct
19 Correct 6 ms 10196 KB Output is correct
20 Correct 6 ms 10324 KB Output is correct
21 Correct 8 ms 10360 KB Output is correct
22 Correct 74 ms 12280 KB Output is correct
23 Correct 67 ms 12276 KB Output is correct
24 Correct 60 ms 11836 KB Output is correct
25 Correct 87 ms 12548 KB Output is correct
26 Correct 55 ms 12592 KB Output is correct
27 Correct 5 ms 10324 KB Output is correct
28 Correct 6 ms 10324 KB Output is correct
29 Correct 6 ms 10324 KB Output is correct
30 Correct 6 ms 10324 KB Output is correct
31 Correct 9 ms 10440 KB Output is correct
32 Correct 7 ms 10284 KB Output is correct
33 Correct 6 ms 10324 KB Output is correct
34 Correct 99 ms 12308 KB Output is correct
35 Correct 128 ms 12600 KB Output is correct
36 Correct 124 ms 12652 KB Output is correct
37 Correct 111 ms 12472 KB Output is correct
38 Correct 68 ms 12536 KB Output is correct
39 Correct 44 ms 11876 KB Output is correct
40 Correct 8 ms 10452 KB Output is correct
41 Correct 9 ms 10448 KB Output is correct
42 Correct 9 ms 10452 KB Output is correct
43 Correct 11 ms 10380 KB Output is correct
44 Correct 149 ms 14752 KB Output is correct
45 Correct 172 ms 14544 KB Output is correct
46 Correct 171 ms 14196 KB Output is correct
47 Correct 157 ms 14688 KB Output is correct
48 Correct 99 ms 14508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10324 KB Output is correct
2 Correct 5 ms 10324 KB Output is correct
3 Correct 7 ms 10244 KB Output is correct
4 Correct 7 ms 10324 KB Output is correct
5 Correct 5 ms 10324 KB Output is correct
6 Correct 5 ms 10324 KB Output is correct
7 Correct 5 ms 10324 KB Output is correct
8 Correct 5 ms 10324 KB Output is correct
9 Correct 5 ms 10196 KB Output is correct
10 Correct 5 ms 10324 KB Output is correct
11 Correct 5 ms 10264 KB Output is correct
12 Correct 5 ms 10324 KB Output is correct
13 Correct 5 ms 10304 KB Output is correct
14 Correct 5 ms 10324 KB Output is correct
15 Correct 5 ms 10324 KB Output is correct
16 Correct 6 ms 10324 KB Output is correct
17 Correct 8 ms 10320 KB Output is correct
18 Correct 5 ms 10324 KB Output is correct
19 Correct 6 ms 10304 KB Output is correct
20 Correct 6 ms 10312 KB Output is correct
21 Correct 5 ms 10324 KB Output is correct
22 Correct 5 ms 10324 KB Output is correct
23 Correct 5 ms 10324 KB Output is correct
24 Correct 6 ms 10324 KB Output is correct
25 Correct 5 ms 10324 KB Output is correct
26 Correct 10 ms 10580 KB Output is correct
27 Correct 11 ms 10572 KB Output is correct
28 Correct 11 ms 10536 KB Output is correct
29 Correct 11 ms 10424 KB Output is correct
30 Correct 9 ms 10448 KB Output is correct
31 Correct 8 ms 10452 KB Output is correct
32 Correct 8 ms 10320 KB Output is correct
33 Correct 10 ms 10452 KB Output is correct
34 Correct 9 ms 10564 KB Output is correct
35 Correct 7 ms 10324 KB Output is correct
36 Correct 6 ms 10324 KB Output is correct
37 Correct 10 ms 10452 KB Output is correct
38 Correct 10 ms 10452 KB Output is correct
39 Correct 6 ms 10280 KB Output is correct
40 Correct 5 ms 10324 KB Output is correct
41 Correct 4 ms 10324 KB Output is correct
42 Correct 5 ms 10196 KB Output is correct
43 Correct 6 ms 10220 KB Output is correct
44 Correct 5 ms 10324 KB Output is correct
45 Correct 6 ms 10324 KB Output is correct
46 Correct 5 ms 10268 KB Output is correct
47 Correct 5 ms 10260 KB Output is correct
48 Correct 5 ms 10196 KB Output is correct
49 Correct 5 ms 10324 KB Output is correct
50 Correct 51 ms 12308 KB Output is correct
51 Correct 36 ms 11704 KB Output is correct
52 Correct 40 ms 12136 KB Output is correct
53 Correct 48 ms 12736 KB Output is correct
54 Correct 47 ms 12596 KB Output is correct
55 Correct 35 ms 13112 KB Output is correct
56 Correct 6 ms 10196 KB Output is correct
57 Correct 6 ms 10324 KB Output is correct
58 Correct 6 ms 10196 KB Output is correct
59 Correct 6 ms 10324 KB Output is correct
60 Correct 8 ms 10360 KB Output is correct
61 Correct 74 ms 12280 KB Output is correct
62 Correct 67 ms 12276 KB Output is correct
63 Correct 60 ms 11836 KB Output is correct
64 Correct 87 ms 12548 KB Output is correct
65 Correct 55 ms 12592 KB Output is correct
66 Correct 5 ms 10324 KB Output is correct
67 Correct 6 ms 10324 KB Output is correct
68 Correct 6 ms 10324 KB Output is correct
69 Correct 6 ms 10324 KB Output is correct
70 Correct 9 ms 10440 KB Output is correct
71 Correct 7 ms 10284 KB Output is correct
72 Correct 6 ms 10324 KB Output is correct
73 Correct 99 ms 12308 KB Output is correct
74 Correct 128 ms 12600 KB Output is correct
75 Correct 124 ms 12652 KB Output is correct
76 Correct 111 ms 12472 KB Output is correct
77 Correct 68 ms 12536 KB Output is correct
78 Correct 44 ms 11876 KB Output is correct
79 Correct 8 ms 10452 KB Output is correct
80 Correct 9 ms 10448 KB Output is correct
81 Correct 9 ms 10452 KB Output is correct
82 Correct 11 ms 10380 KB Output is correct
83 Correct 149 ms 14752 KB Output is correct
84 Correct 172 ms 14544 KB Output is correct
85 Correct 171 ms 14196 KB Output is correct
86 Correct 157 ms 14688 KB Output is correct
87 Correct 99 ms 14508 KB Output is correct
88 Correct 311 ms 25820 KB Output is correct
89 Correct 287 ms 19788 KB Output is correct
90 Correct 259 ms 21696 KB Output is correct
91 Correct 281 ms 18624 KB Output is correct
92 Correct 245 ms 15576 KB Output is correct
93 Correct 298 ms 20476 KB Output is correct
94 Correct 272 ms 17684 KB Output is correct
95 Correct 129 ms 18260 KB Output is correct
96 Correct 280 ms 25568 KB Output is correct
97 Correct 55 ms 15672 KB Output is correct
98 Correct 162 ms 17372 KB Output is correct
99 Correct 182 ms 17212 KB Output is correct