답안 #544545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544545 2022-04-02T09:32:07 Z benson1029 Team Contest (JOI22_team) C++14
100 / 100
700 ms 17988 KB
#include<bits/stdc++.h>
using namespace std;

int n;
vector<int> v[150005];
vector< pair<int,int> > a[3];
int seg1[600005], seg2[600005];
int mp[3][150005];

void seg1_upd(int x, int l, int r, int ll, int rr, int val) {
	if(ll <= l && r <= rr) {
		seg1[x] = max(seg1[x], val);
	} else if(ll > r || rr < l) {
		return;
	} else {
		seg1_upd(x*2, l, (l+r)/2, ll, rr, val);
		seg1_upd(x*2+1, (l+r)/2+1, r, ll, rr, val);
	}
}

void seg2_upd(int x, int l, int r, int ll, int rr, int val) {
	if(seg2[x] == 0) seg2[x] = 1e9;
	if(ll <= l && r <= rr) {
		seg2[x] = min(seg2[x], val);
	} else if(ll > r || rr < l) {
		return;
	} else {
		seg2_upd(x*2, l, (l+r)/2, ll, rr, val);
		seg2_upd(x*2+1, (l+r)/2+1, r, ll, rr, val);
	}
}

int seg1_qry(int x, int l, int r, int pos) {
	int tmp = seg1[x];
	if(l != r) {
		if(pos <= (l+r)/2) tmp = max(tmp, seg1_qry(x*2, l, (l+r)/2, pos));
		else tmp = max(tmp, seg1_qry(x*2+1, (l+r)/2+1, r, pos));
	}
	return tmp;
}

int seg2_qry(int x, int l, int r, int pos) {
	if(seg2[x] == 0) seg2[x] = 1e9;
	int tmp = seg2[x];
	if(l != r) {
		if(pos <= (l+r)/2) tmp = min(tmp, seg2_qry(x*2, l, (l+r)/2, pos));
		else tmp = min(tmp, seg2_qry(x*2+1, (l+r)/2+1, r, pos));
	}
	return tmp;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; i++) {
		v[i].resize(3);
		cin >> v[i][0] >> v[i][1] >> v[i][2];
		a[0].push_back({v[i][0], i});
		a[1].push_back({v[i][1], i});
		a[2].push_back({v[i][2], i});
	}
	sort(a[0].begin(), a[0].end());
	sort(a[1].begin(), a[1].end());
	sort(a[2].begin(), a[2].end());
	for(int i=0; i<3; i++) {
		int tmp = 0;
		for(int j=0; j<n; j++) {
			if(j==0 || a[i][j].first!=a[i][j-1].first) tmp++;
			mp[i][tmp] = a[i][j].first;
			v[a[i][j].second][i] = tmp;
		}
	}
	sort(v, v+n);
	
	int ans = -1;
	int pos = 0; 
	
	for(int i=0; i<n; i++) {
		
		if(pos>0) {
			if(pos > v[i][1] && seg1_qry(1, 1, n, pos) > v[i][2]) {
				//cout << seg1_qry(1, 1, n, l) << " " << seg2_qry(1, 1, n, l) << "\n";
				ans = max(ans, mp[2][seg1_qry(1, 1, n, pos)] + mp[1][pos] + mp[0][v[i][0]]);
			}
		}
		
		if(i<n-1 && v[i][0] != v[i+1][0]) {
			for(int j=i; (j>=0 && v[j][0]==v[i][0]); j--) {
				seg2_upd(1, 1, n, 1, v[j][1], v[j][2]);
				seg1_upd(1, 1, n, v[j][1]+1, n, v[j][2]);
				
				int l,r,mid;
				l = v[j][1]+1; r = n;
				while(l<r) {
					mid = (l+r+1)/2;
					if(seg1_qry(1, 1, n, mid) > v[j][2]) r = mid - 1;
					else l = mid;
				}
				
				if(l<=n && seg1_qry(1, 1, n, l) == v[j][2]) {
					r = l; l = v[j][1] + 1;
					while(l<r) {
						mid = (l+r+1)/2;
						if(seg2_qry(1, 1, n, mid) >= v[j][2]) r = mid - 1;
						else l = mid;
					}
					if(seg2_qry(1, 1, n, l) < v[j][2]) {
						pos = max(pos, l);
					}
				}
				
				if(seg1_qry(1, 1, n, v[j][1]) > seg2_qry(1, 1, n, v[j][1])) {
					pos = max(pos, v[j][1]);
				}
			}
		}
		
	}
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3836 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 4 ms 3796 KB Output is correct
9 Correct 4 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 4 ms 3796 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 3 ms 3796 KB Output is correct
16 Correct 3 ms 3796 KB Output is correct
17 Correct 5 ms 3796 KB Output is correct
18 Correct 5 ms 3796 KB Output is correct
19 Correct 3 ms 3796 KB Output is correct
20 Correct 5 ms 3796 KB Output is correct
21 Correct 2 ms 3796 KB Output is correct
22 Correct 5 ms 3796 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 3 ms 3796 KB Output is correct
25 Correct 3 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3836 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 4 ms 3796 KB Output is correct
9 Correct 4 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 4 ms 3796 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 3 ms 3796 KB Output is correct
16 Correct 3 ms 3796 KB Output is correct
17 Correct 5 ms 3796 KB Output is correct
18 Correct 5 ms 3796 KB Output is correct
19 Correct 3 ms 3796 KB Output is correct
20 Correct 5 ms 3796 KB Output is correct
21 Correct 2 ms 3796 KB Output is correct
22 Correct 5 ms 3796 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 3 ms 3796 KB Output is correct
25 Correct 3 ms 3796 KB Output is correct
26 Correct 9 ms 4180 KB Output is correct
27 Correct 10 ms 4180 KB Output is correct
28 Correct 11 ms 4180 KB Output is correct
29 Correct 12 ms 4180 KB Output is correct
30 Correct 11 ms 4116 KB Output is correct
31 Correct 15 ms 4052 KB Output is correct
32 Correct 11 ms 4144 KB Output is correct
33 Correct 6 ms 4052 KB Output is correct
34 Correct 13 ms 4212 KB Output is correct
35 Correct 4 ms 3924 KB Output is correct
36 Correct 4 ms 3924 KB Output is correct
37 Correct 10 ms 4052 KB Output is correct
38 Correct 12 ms 4104 KB Output is correct
39 Correct 5 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 4 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 3 ms 3796 KB Output is correct
11 Correct 328 ms 12200 KB Output is correct
12 Correct 251 ms 9460 KB Output is correct
13 Correct 256 ms 10816 KB Output is correct
14 Correct 320 ms 12252 KB Output is correct
15 Correct 209 ms 12252 KB Output is correct
16 Correct 63 ms 12020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 4 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 3 ms 3796 KB Output is correct
11 Correct 328 ms 12200 KB Output is correct
12 Correct 251 ms 9460 KB Output is correct
13 Correct 256 ms 10816 KB Output is correct
14 Correct 320 ms 12252 KB Output is correct
15 Correct 209 ms 12252 KB Output is correct
16 Correct 63 ms 12020 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3808 KB Output is correct
20 Correct 3 ms 3796 KB Output is correct
21 Correct 5 ms 3964 KB Output is correct
22 Correct 383 ms 12332 KB Output is correct
23 Correct 368 ms 12076 KB Output is correct
24 Correct 292 ms 9948 KB Output is correct
25 Correct 390 ms 12188 KB Output is correct
26 Correct 218 ms 12204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 4 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 3 ms 3796 KB Output is correct
11 Correct 328 ms 12200 KB Output is correct
12 Correct 251 ms 9460 KB Output is correct
13 Correct 256 ms 10816 KB Output is correct
14 Correct 320 ms 12252 KB Output is correct
15 Correct 209 ms 12252 KB Output is correct
16 Correct 63 ms 12020 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3808 KB Output is correct
20 Correct 3 ms 3796 KB Output is correct
21 Correct 5 ms 3964 KB Output is correct
22 Correct 383 ms 12332 KB Output is correct
23 Correct 368 ms 12076 KB Output is correct
24 Correct 292 ms 9948 KB Output is correct
25 Correct 390 ms 12188 KB Output is correct
26 Correct 218 ms 12204 KB Output is correct
27 Correct 3 ms 3796 KB Output is correct
28 Correct 3 ms 3796 KB Output is correct
29 Correct 3 ms 3796 KB Output is correct
30 Correct 3 ms 3796 KB Output is correct
31 Correct 11 ms 4140 KB Output is correct
32 Correct 4 ms 3956 KB Output is correct
33 Correct 4 ms 3924 KB Output is correct
34 Correct 434 ms 12000 KB Output is correct
35 Correct 411 ms 12000 KB Output is correct
36 Correct 505 ms 12344 KB Output is correct
37 Correct 493 ms 12164 KB Output is correct
38 Correct 222 ms 12076 KB Output is correct
39 Correct 49 ms 8792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 4 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 3 ms 3796 KB Output is correct
11 Correct 328 ms 12200 KB Output is correct
12 Correct 251 ms 9460 KB Output is correct
13 Correct 256 ms 10816 KB Output is correct
14 Correct 320 ms 12252 KB Output is correct
15 Correct 209 ms 12252 KB Output is correct
16 Correct 63 ms 12020 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3808 KB Output is correct
20 Correct 3 ms 3796 KB Output is correct
21 Correct 5 ms 3964 KB Output is correct
22 Correct 383 ms 12332 KB Output is correct
23 Correct 368 ms 12076 KB Output is correct
24 Correct 292 ms 9948 KB Output is correct
25 Correct 390 ms 12188 KB Output is correct
26 Correct 218 ms 12204 KB Output is correct
27 Correct 3 ms 3796 KB Output is correct
28 Correct 3 ms 3796 KB Output is correct
29 Correct 3 ms 3796 KB Output is correct
30 Correct 3 ms 3796 KB Output is correct
31 Correct 11 ms 4140 KB Output is correct
32 Correct 4 ms 3956 KB Output is correct
33 Correct 4 ms 3924 KB Output is correct
34 Correct 434 ms 12000 KB Output is correct
35 Correct 411 ms 12000 KB Output is correct
36 Correct 505 ms 12344 KB Output is correct
37 Correct 493 ms 12164 KB Output is correct
38 Correct 222 ms 12076 KB Output is correct
39 Correct 49 ms 8792 KB Output is correct
40 Correct 9 ms 4120 KB Output is correct
41 Correct 10 ms 4052 KB Output is correct
42 Correct 14 ms 4052 KB Output is correct
43 Correct 11 ms 4052 KB Output is correct
44 Correct 520 ms 12724 KB Output is correct
45 Correct 551 ms 12588 KB Output is correct
46 Correct 540 ms 12492 KB Output is correct
47 Correct 567 ms 12500 KB Output is correct
48 Correct 249 ms 12240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3836 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 4 ms 3796 KB Output is correct
9 Correct 4 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 4 ms 3796 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 3 ms 3796 KB Output is correct
16 Correct 3 ms 3796 KB Output is correct
17 Correct 5 ms 3796 KB Output is correct
18 Correct 5 ms 3796 KB Output is correct
19 Correct 3 ms 3796 KB Output is correct
20 Correct 5 ms 3796 KB Output is correct
21 Correct 2 ms 3796 KB Output is correct
22 Correct 5 ms 3796 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 3 ms 3796 KB Output is correct
25 Correct 3 ms 3796 KB Output is correct
26 Correct 9 ms 4180 KB Output is correct
27 Correct 10 ms 4180 KB Output is correct
28 Correct 11 ms 4180 KB Output is correct
29 Correct 12 ms 4180 KB Output is correct
30 Correct 11 ms 4116 KB Output is correct
31 Correct 15 ms 4052 KB Output is correct
32 Correct 11 ms 4144 KB Output is correct
33 Correct 6 ms 4052 KB Output is correct
34 Correct 13 ms 4212 KB Output is correct
35 Correct 4 ms 3924 KB Output is correct
36 Correct 4 ms 3924 KB Output is correct
37 Correct 10 ms 4052 KB Output is correct
38 Correct 12 ms 4104 KB Output is correct
39 Correct 5 ms 3924 KB Output is correct
40 Correct 3 ms 3796 KB Output is correct
41 Correct 2 ms 3796 KB Output is correct
42 Correct 2 ms 3796 KB Output is correct
43 Correct 2 ms 3796 KB Output is correct
44 Correct 2 ms 3796 KB Output is correct
45 Correct 2 ms 3796 KB Output is correct
46 Correct 4 ms 3796 KB Output is correct
47 Correct 2 ms 3796 KB Output is correct
48 Correct 2 ms 3796 KB Output is correct
49 Correct 3 ms 3796 KB Output is correct
50 Correct 328 ms 12200 KB Output is correct
51 Correct 251 ms 9460 KB Output is correct
52 Correct 256 ms 10816 KB Output is correct
53 Correct 320 ms 12252 KB Output is correct
54 Correct 209 ms 12252 KB Output is correct
55 Correct 63 ms 12020 KB Output is correct
56 Correct 2 ms 3796 KB Output is correct
57 Correct 2 ms 3796 KB Output is correct
58 Correct 2 ms 3808 KB Output is correct
59 Correct 3 ms 3796 KB Output is correct
60 Correct 5 ms 3964 KB Output is correct
61 Correct 383 ms 12332 KB Output is correct
62 Correct 368 ms 12076 KB Output is correct
63 Correct 292 ms 9948 KB Output is correct
64 Correct 390 ms 12188 KB Output is correct
65 Correct 218 ms 12204 KB Output is correct
66 Correct 3 ms 3796 KB Output is correct
67 Correct 3 ms 3796 KB Output is correct
68 Correct 3 ms 3796 KB Output is correct
69 Correct 3 ms 3796 KB Output is correct
70 Correct 11 ms 4140 KB Output is correct
71 Correct 4 ms 3956 KB Output is correct
72 Correct 4 ms 3924 KB Output is correct
73 Correct 434 ms 12000 KB Output is correct
74 Correct 411 ms 12000 KB Output is correct
75 Correct 505 ms 12344 KB Output is correct
76 Correct 493 ms 12164 KB Output is correct
77 Correct 222 ms 12076 KB Output is correct
78 Correct 49 ms 8792 KB Output is correct
79 Correct 9 ms 4120 KB Output is correct
80 Correct 10 ms 4052 KB Output is correct
81 Correct 14 ms 4052 KB Output is correct
82 Correct 11 ms 4052 KB Output is correct
83 Correct 520 ms 12724 KB Output is correct
84 Correct 551 ms 12588 KB Output is correct
85 Correct 540 ms 12492 KB Output is correct
86 Correct 567 ms 12500 KB Output is correct
87 Correct 249 ms 12240 KB Output is correct
88 Correct 593 ms 17988 KB Output is correct
89 Correct 611 ms 15628 KB Output is correct
90 Correct 602 ms 16000 KB Output is correct
91 Correct 622 ms 15036 KB Output is correct
92 Correct 571 ms 13552 KB Output is correct
93 Correct 632 ms 15788 KB Output is correct
94 Correct 639 ms 14480 KB Output is correct
95 Correct 255 ms 12696 KB Output is correct
96 Correct 700 ms 17872 KB Output is correct
97 Correct 81 ms 12072 KB Output is correct
98 Correct 504 ms 14720 KB Output is correct
99 Correct 577 ms 14908 KB Output is correct