Submission #796686

# Submission time Handle Problem Language Result Execution time Memory
796686 2023-07-28T15:40:02 Z MetalPower Team Contest (JOI22_team) C++17
100 / 100
321 ms 26516 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define fi first
#define se second

const int MX = 150069;
const int INF = 1e9 + 7;

int N, arr[MX][3];
vector<int> cc[3];
vector<pii> ls[MX], cm;
set<pii> s;

struct segmax{
	int st[MX << 1];

	void build(){
		for(int i = 0; i < (MX << 1); i++) st[i] = -INF;
	}

	void upd(int p, int v){
		for(p += MX, st[p] = v, p >>= 1; p > 0; p >>= 1) st[p] = max(st[p << 1], st[p << 1|1]);
	}

	int que(int l, int r){
		int res = -INF;
		for(l += MX, r += MX + 1; l < r; l >>= 1, r >>= 1){
			if(l & 1) res = max(res, st[l++]);
			if(r & 1) res = max(res, st[--r]);
		}
		return res;
	}
} sx;

struct segmin{
	int st[MX << 1];

	void build(){
		for(int i = 0; i < (MX << 1); i++) st[i] = INF;
	}

	void upd(int p, int v){
		for(p += MX, st[p] = v, p >>= 1; p > 0; p >>= 1) st[p] = min(st[p << 1], st[p << 1|1]);
	}

	int que(int l, int r){
		int res = INF;
		for(l += MX, r += MX + 1; l < r; l >>= 1, r >>= 1){
			if(l & 1) res = min(res, st[l++]);
			if(r & 1) res = min(res, st[--r]);
		}
		return res;
	}
} sn;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> N;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 3; j++){
			cin >> arr[i][j];
			cc[j].push_back(arr[i][j]);
		}
	}

	for(int j = 0; j < 3; j++){
		sort(cc[j].begin(), cc[j].end());
		cc[j].resize(unique(cc[j].begin(), cc[j].end()) - cc[j].begin());
	}

	for(int i = 0; i < N; i++){
		for(int j = 0; j < 3; j++) arr[i][j] = lower_bound(cc[j].begin(), cc[j].end(), arr[i][j]) - cc[j].begin();
		ls[arr[i][0]].push_back({arr[i][1], arr[i][2]});
		cm.push_back({arr[i][1], arr[i][2]});
	}

	sort(cm.begin(), cm.end());
	cm.resize(unique(cm.begin(), cm.end()) - cm.begin());

	int mx = -1, ans = -1;

	sx.build();
	sn.build();

	set<pii> s;

	for(int i = 0; i < N; i++){
		
		for(pii x : ls[i]){ // query

			if(mx == -1) continue;

			int lf = sx.que(0, mx);
			int l = mx + 1, r = N - 1, rg = -1;
			while(l <= r){
				int mid = l + r >> 1, curr = sn.que(mid, r);
				if(curr < lf) rg = mid, l = mid + 1;
				else r = mid - 1;
			}

			if(cm[rg].fi > x.fi && lf > x.se) ans = max(ans, cc[0][i] + cc[1][cm[rg].fi] + cc[2][lf]); 
		}

		for(pii x : ls[i]){ // update

			int idx = lower_bound(cm.begin(), cm.end(), x) - cm.begin();

			s.insert(x);
			set<pii>::iterator it = s.find(x);

			{
				it++;
				if(it != s.end() && x.se > (*it).se) mx = max(mx, idx);
				it--;
				if(it != s.begin()){
					it--;
					if((*it).se > x.se) mx = max(mx, (int) (lower_bound(cm.begin(), cm.end(), (*it)) - cm.begin()));
				}
			}

			sx.upd(idx, x.se);
			sn.upd(idx, x.se);
		}
	}

	cout << ans << '\n';
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:99:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   99 |     int mid = l + r >> 1, curr = sn.que(mid, r);
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6140 KB Output is correct
4 Correct 3 ms 6100 KB Output is correct
5 Correct 3 ms 6100 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 3 ms 6156 KB Output is correct
9 Correct 3 ms 6100 KB Output is correct
10 Correct 3 ms 6156 KB Output is correct
11 Correct 3 ms 6156 KB Output is correct
12 Correct 3 ms 6168 KB Output is correct
13 Correct 3 ms 6100 KB Output is correct
14 Correct 3 ms 6228 KB Output is correct
15 Correct 3 ms 6160 KB Output is correct
16 Correct 3 ms 6228 KB Output is correct
17 Correct 3 ms 6228 KB Output is correct
18 Correct 4 ms 6228 KB Output is correct
19 Correct 3 ms 6228 KB Output is correct
20 Correct 3 ms 6228 KB Output is correct
21 Correct 3 ms 6228 KB Output is correct
22 Correct 4 ms 6160 KB Output is correct
23 Correct 3 ms 6228 KB Output is correct
24 Correct 3 ms 6228 KB Output is correct
25 Correct 3 ms 6228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6140 KB Output is correct
4 Correct 3 ms 6100 KB Output is correct
5 Correct 3 ms 6100 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 3 ms 6156 KB Output is correct
9 Correct 3 ms 6100 KB Output is correct
10 Correct 3 ms 6156 KB Output is correct
11 Correct 3 ms 6156 KB Output is correct
12 Correct 3 ms 6168 KB Output is correct
13 Correct 3 ms 6100 KB Output is correct
14 Correct 3 ms 6228 KB Output is correct
15 Correct 3 ms 6160 KB Output is correct
16 Correct 3 ms 6228 KB Output is correct
17 Correct 3 ms 6228 KB Output is correct
18 Correct 4 ms 6228 KB Output is correct
19 Correct 3 ms 6228 KB Output is correct
20 Correct 3 ms 6228 KB Output is correct
21 Correct 3 ms 6228 KB Output is correct
22 Correct 4 ms 6160 KB Output is correct
23 Correct 3 ms 6228 KB Output is correct
24 Correct 3 ms 6228 KB Output is correct
25 Correct 3 ms 6228 KB Output is correct
26 Correct 10 ms 6680 KB Output is correct
27 Correct 8 ms 6680 KB Output is correct
28 Correct 8 ms 6628 KB Output is correct
29 Correct 8 ms 6620 KB Output is correct
30 Correct 6 ms 6516 KB Output is correct
31 Correct 8 ms 6620 KB Output is correct
32 Correct 7 ms 6484 KB Output is correct
33 Correct 6 ms 6552 KB Output is correct
34 Correct 7 ms 6740 KB Output is correct
35 Correct 3 ms 6228 KB Output is correct
36 Correct 3 ms 6292 KB Output is correct
37 Correct 6 ms 6484 KB Output is correct
38 Correct 7 ms 6484 KB Output is correct
39 Correct 5 ms 6228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6100 KB Output is correct
4 Correct 3 ms 6160 KB Output is correct
5 Correct 2 ms 6160 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 4 ms 6164 KB Output is correct
9 Correct 4 ms 6160 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 94 ms 13312 KB Output is correct
12 Correct 56 ms 11252 KB Output is correct
13 Correct 57 ms 12064 KB Output is correct
14 Correct 81 ms 14024 KB Output is correct
15 Correct 70 ms 13480 KB Output is correct
16 Correct 47 ms 13092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6100 KB Output is correct
4 Correct 3 ms 6160 KB Output is correct
5 Correct 2 ms 6160 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 4 ms 6164 KB Output is correct
9 Correct 4 ms 6160 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 94 ms 13312 KB Output is correct
12 Correct 56 ms 11252 KB Output is correct
13 Correct 57 ms 12064 KB Output is correct
14 Correct 81 ms 14024 KB Output is correct
15 Correct 70 ms 13480 KB Output is correct
16 Correct 47 ms 13092 KB Output is correct
17 Correct 3 ms 6100 KB Output is correct
18 Correct 4 ms 6100 KB Output is correct
19 Correct 4 ms 6160 KB Output is correct
20 Correct 5 ms 6156 KB Output is correct
21 Correct 6 ms 6228 KB Output is correct
22 Correct 129 ms 13444 KB Output is correct
23 Correct 115 ms 13172 KB Output is correct
24 Correct 90 ms 11640 KB Output is correct
25 Correct 112 ms 13884 KB Output is correct
26 Correct 57 ms 13188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6100 KB Output is correct
4 Correct 3 ms 6160 KB Output is correct
5 Correct 2 ms 6160 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 4 ms 6164 KB Output is correct
9 Correct 4 ms 6160 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 94 ms 13312 KB Output is correct
12 Correct 56 ms 11252 KB Output is correct
13 Correct 57 ms 12064 KB Output is correct
14 Correct 81 ms 14024 KB Output is correct
15 Correct 70 ms 13480 KB Output is correct
16 Correct 47 ms 13092 KB Output is correct
17 Correct 3 ms 6100 KB Output is correct
18 Correct 4 ms 6100 KB Output is correct
19 Correct 4 ms 6160 KB Output is correct
20 Correct 5 ms 6156 KB Output is correct
21 Correct 6 ms 6228 KB Output is correct
22 Correct 129 ms 13444 KB Output is correct
23 Correct 115 ms 13172 KB Output is correct
24 Correct 90 ms 11640 KB Output is correct
25 Correct 112 ms 13884 KB Output is correct
26 Correct 57 ms 13188 KB Output is correct
27 Correct 3 ms 6228 KB Output is correct
28 Correct 3 ms 6160 KB Output is correct
29 Correct 3 ms 6228 KB Output is correct
30 Correct 3 ms 6228 KB Output is correct
31 Correct 7 ms 6516 KB Output is correct
32 Correct 4 ms 6228 KB Output is correct
33 Correct 4 ms 6228 KB Output is correct
34 Correct 206 ms 16768 KB Output is correct
35 Correct 208 ms 16060 KB Output is correct
36 Correct 204 ms 16204 KB Output is correct
37 Correct 166 ms 15980 KB Output is correct
38 Correct 73 ms 13764 KB Output is correct
39 Correct 70 ms 14864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6100 KB Output is correct
4 Correct 3 ms 6160 KB Output is correct
5 Correct 2 ms 6160 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 4 ms 6164 KB Output is correct
9 Correct 4 ms 6160 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 94 ms 13312 KB Output is correct
12 Correct 56 ms 11252 KB Output is correct
13 Correct 57 ms 12064 KB Output is correct
14 Correct 81 ms 14024 KB Output is correct
15 Correct 70 ms 13480 KB Output is correct
16 Correct 47 ms 13092 KB Output is correct
17 Correct 3 ms 6100 KB Output is correct
18 Correct 4 ms 6100 KB Output is correct
19 Correct 4 ms 6160 KB Output is correct
20 Correct 5 ms 6156 KB Output is correct
21 Correct 6 ms 6228 KB Output is correct
22 Correct 129 ms 13444 KB Output is correct
23 Correct 115 ms 13172 KB Output is correct
24 Correct 90 ms 11640 KB Output is correct
25 Correct 112 ms 13884 KB Output is correct
26 Correct 57 ms 13188 KB Output is correct
27 Correct 3 ms 6228 KB Output is correct
28 Correct 3 ms 6160 KB Output is correct
29 Correct 3 ms 6228 KB Output is correct
30 Correct 3 ms 6228 KB Output is correct
31 Correct 7 ms 6516 KB Output is correct
32 Correct 4 ms 6228 KB Output is correct
33 Correct 4 ms 6228 KB Output is correct
34 Correct 206 ms 16768 KB Output is correct
35 Correct 208 ms 16060 KB Output is correct
36 Correct 204 ms 16204 KB Output is correct
37 Correct 166 ms 15980 KB Output is correct
38 Correct 73 ms 13764 KB Output is correct
39 Correct 70 ms 14864 KB Output is correct
40 Correct 6 ms 6420 KB Output is correct
41 Correct 10 ms 6624 KB Output is correct
42 Correct 7 ms 6484 KB Output is correct
43 Correct 7 ms 6468 KB Output is correct
44 Correct 262 ms 21868 KB Output is correct
45 Correct 229 ms 19700 KB Output is correct
46 Correct 257 ms 20356 KB Output is correct
47 Correct 223 ms 19600 KB Output is correct
48 Correct 102 ms 14532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 3 ms 6140 KB Output is correct
4 Correct 3 ms 6100 KB Output is correct
5 Correct 3 ms 6100 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 3 ms 6156 KB Output is correct
9 Correct 3 ms 6100 KB Output is correct
10 Correct 3 ms 6156 KB Output is correct
11 Correct 3 ms 6156 KB Output is correct
12 Correct 3 ms 6168 KB Output is correct
13 Correct 3 ms 6100 KB Output is correct
14 Correct 3 ms 6228 KB Output is correct
15 Correct 3 ms 6160 KB Output is correct
16 Correct 3 ms 6228 KB Output is correct
17 Correct 3 ms 6228 KB Output is correct
18 Correct 4 ms 6228 KB Output is correct
19 Correct 3 ms 6228 KB Output is correct
20 Correct 3 ms 6228 KB Output is correct
21 Correct 3 ms 6228 KB Output is correct
22 Correct 4 ms 6160 KB Output is correct
23 Correct 3 ms 6228 KB Output is correct
24 Correct 3 ms 6228 KB Output is correct
25 Correct 3 ms 6228 KB Output is correct
26 Correct 10 ms 6680 KB Output is correct
27 Correct 8 ms 6680 KB Output is correct
28 Correct 8 ms 6628 KB Output is correct
29 Correct 8 ms 6620 KB Output is correct
30 Correct 6 ms 6516 KB Output is correct
31 Correct 8 ms 6620 KB Output is correct
32 Correct 7 ms 6484 KB Output is correct
33 Correct 6 ms 6552 KB Output is correct
34 Correct 7 ms 6740 KB Output is correct
35 Correct 3 ms 6228 KB Output is correct
36 Correct 3 ms 6292 KB Output is correct
37 Correct 6 ms 6484 KB Output is correct
38 Correct 7 ms 6484 KB Output is correct
39 Correct 5 ms 6228 KB Output is correct
40 Correct 3 ms 6100 KB Output is correct
41 Correct 3 ms 6100 KB Output is correct
42 Correct 3 ms 6100 KB Output is correct
43 Correct 3 ms 6160 KB Output is correct
44 Correct 2 ms 6160 KB Output is correct
45 Correct 3 ms 6100 KB Output is correct
46 Correct 3 ms 6100 KB Output is correct
47 Correct 4 ms 6164 KB Output is correct
48 Correct 4 ms 6160 KB Output is correct
49 Correct 3 ms 6100 KB Output is correct
50 Correct 94 ms 13312 KB Output is correct
51 Correct 56 ms 11252 KB Output is correct
52 Correct 57 ms 12064 KB Output is correct
53 Correct 81 ms 14024 KB Output is correct
54 Correct 70 ms 13480 KB Output is correct
55 Correct 47 ms 13092 KB Output is correct
56 Correct 3 ms 6100 KB Output is correct
57 Correct 4 ms 6100 KB Output is correct
58 Correct 4 ms 6160 KB Output is correct
59 Correct 5 ms 6156 KB Output is correct
60 Correct 6 ms 6228 KB Output is correct
61 Correct 129 ms 13444 KB Output is correct
62 Correct 115 ms 13172 KB Output is correct
63 Correct 90 ms 11640 KB Output is correct
64 Correct 112 ms 13884 KB Output is correct
65 Correct 57 ms 13188 KB Output is correct
66 Correct 3 ms 6228 KB Output is correct
67 Correct 3 ms 6160 KB Output is correct
68 Correct 3 ms 6228 KB Output is correct
69 Correct 3 ms 6228 KB Output is correct
70 Correct 7 ms 6516 KB Output is correct
71 Correct 4 ms 6228 KB Output is correct
72 Correct 4 ms 6228 KB Output is correct
73 Correct 206 ms 16768 KB Output is correct
74 Correct 208 ms 16060 KB Output is correct
75 Correct 204 ms 16204 KB Output is correct
76 Correct 166 ms 15980 KB Output is correct
77 Correct 73 ms 13764 KB Output is correct
78 Correct 70 ms 14864 KB Output is correct
79 Correct 6 ms 6420 KB Output is correct
80 Correct 10 ms 6624 KB Output is correct
81 Correct 7 ms 6484 KB Output is correct
82 Correct 7 ms 6468 KB Output is correct
83 Correct 262 ms 21868 KB Output is correct
84 Correct 229 ms 19700 KB Output is correct
85 Correct 257 ms 20356 KB Output is correct
86 Correct 223 ms 19600 KB Output is correct
87 Correct 102 ms 14532 KB Output is correct
88 Correct 302 ms 26516 KB Output is correct
89 Correct 321 ms 24416 KB Output is correct
90 Correct 321 ms 24852 KB Output is correct
91 Correct 300 ms 23868 KB Output is correct
92 Correct 284 ms 22188 KB Output is correct
93 Correct 304 ms 23400 KB Output is correct
94 Correct 264 ms 22204 KB Output is correct
95 Correct 138 ms 20160 KB Output is correct
96 Correct 212 ms 26468 KB Output is correct
97 Correct 63 ms 16068 KB Output is correct
98 Correct 120 ms 20392 KB Output is correct
99 Correct 195 ms 20464 KB Output is correct