답안 #772902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
772902 2023-07-04T12:34:16 Z raysh07 Team Contest (JOI22_team) C++17
100 / 100
653 ms 52296 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

struct info{
	int a, b, c;
};

const int N = 1.5e5 + 69;
int seg[4 * N][3], n;
int inv[N][3], tim = 0;

void upd(int l, int r, int pos, int qp, int v, int i){
	if (l == r){
		seg[pos][i] = max(seg[pos][i], v);
		return;
	}

	int mid = (l + r)/2;
	if (qp <= mid) upd(l, mid, pos*2, qp, v, i);
	else upd(mid + 1, r, pos*2 + 1, qp, v, i);

	seg[pos][i] = max(seg[pos * 2][i], seg[pos * 2 + 1][i]);
}

int query(int l, int r, int pos, int ql, int qr, int i){
	if (l >= ql && r <= qr) return seg[pos][i];
	else if (l > qr || r < ql) return 0;

	int mid = (l + r)/2;
	return max(query(l, mid, pos*2, ql, qr, i), query(mid + 1, r, pos*2 + 1, ql, qr, i));
}

void compress(vector <int> &a){
	set <int> st;
	map <int, int> mp;
	for (auto x : a) st.insert(x);

	int pr = 0;
	for (auto x : st) {
		mp[x] = ++pr;
		inv[pr][tim] = x;
	}
	tim++;
	for (auto &x : a) x = mp[x];
}

void Solve()
{
	cin >> n;

	vector <int> a(n), b(n), c(n);

	for (int i = 1; i <= n; i++){
		cin >> a[i - 1] >> b[i - 1] >> c[i - 1];
	}

	compress(a);
	compress(b);
	compress(c);

	vector <info> v(n);
	for (int i = 0; i < n; i++){
		v[i].a = a[i];
		v[i].b = b[i];
		v[i].c = c[i];
	}

	sort(v.begin(), v.end(), [&](info x, info y){
		return x.a < y.a;
	});

	vector <info> todo, good;

	//go in increasing a 
	//position stuff with c 
	//find max b possible 
	for (auto x : v){
		if (todo.size() && todo[0].a != x.a){
			for (auto y : todo){
				upd(1, n, 1, y.c, y.b, 0);
			}
			todo.clear();
		}

		int mxb = query(1, n, 1, 1, x.c, 0);
	//	cout << mxb << " ";
		if (mxb > x.b) {
			info ok;
			ok.a = x.a;
			ok.b = mxb;
			ok.c = x.c;
			good.push_back(ok);
		}
		todo.push_back(x);
	}
//	cout << "\n";
	todo.clear();
	sort(v.begin(), v.end(), [&](info x, info y){
		return x.b < y.b;
	});

	for (auto x : v){
		if (todo.size() && todo[0].b != x.b){
			for (auto y : todo){
				upd(1, n, 1, y.c, y.a, 1);
			}
			todo.clear();
		}

		int mxa = query(1, n, 1, 1, x.c, 1);
		if (mxa > x.a){
			info ok;
			ok.a = mxa;
			ok.b = x.b;
			ok.c = x.c;
			good.push_back(ok);
		}
		todo.push_back(x);
	}

	int ans = -1;
	
// 	for (auto x : good){
// 	    cout << x.a << " " << x.b << " " << x.c << "\n";
// 	}
	//sort by x, query only useful y 

	sort(good.begin(), good.end(), [&](info x, info y){
		return x.a < y.a;
	});

	sort(v.begin(), v.end(), [&](info x, info y){
		return x.a < y.a;
	});

	int ptr = 0;
	for (auto x : good){
		while (ptr != v.size() && v[ptr].a < x.a){
		  //  cout << "ADDED " << x.b << " " << x.c << "\n";
			upd(1, n, 1, v[ptr].b, v[ptr].c, 2);
			ptr++;
		}

		int mxc = query(1, n, 1, 1, x.b - 1, 2);
	//	cout << "QUERYING " << x.b << " " << x.c << "\n";
		if (mxc > x.c){
			ans = max(ans, inv[x.a][0] + inv[x.b][1] + inv[mxc][2]);
		}
	}

	cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}

Compilation message

team.cpp: In function 'void Solve()':
team.cpp:144:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<info>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |   while (ptr != v.size() && v[ptr].a < x.a){
      |          ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 416 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 416 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 12 ms 1440 KB Output is correct
27 Correct 9 ms 1240 KB Output is correct
28 Correct 7 ms 1100 KB Output is correct
29 Correct 6 ms 920 KB Output is correct
30 Correct 5 ms 896 KB Output is correct
31 Correct 6 ms 992 KB Output is correct
32 Correct 5 ms 724 KB Output is correct
33 Correct 4 ms 852 KB Output is correct
34 Correct 7 ms 1236 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 4 ms 824 KB Output is correct
38 Correct 4 ms 724 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 130 ms 14352 KB Output is correct
12 Correct 80 ms 8192 KB Output is correct
13 Correct 95 ms 10304 KB Output is correct
14 Correct 116 ms 12448 KB Output is correct
15 Correct 77 ms 15700 KB Output is correct
16 Correct 62 ms 14524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 130 ms 14352 KB Output is correct
12 Correct 80 ms 8192 KB Output is correct
13 Correct 95 ms 10304 KB Output is correct
14 Correct 116 ms 12448 KB Output is correct
15 Correct 77 ms 15700 KB Output is correct
16 Correct 62 ms 14524 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 156 ms 21144 KB Output is correct
23 Correct 143 ms 14800 KB Output is correct
24 Correct 102 ms 9576 KB Output is correct
25 Correct 138 ms 15224 KB Output is correct
26 Correct 87 ms 15680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 130 ms 14352 KB Output is correct
12 Correct 80 ms 8192 KB Output is correct
13 Correct 95 ms 10304 KB Output is correct
14 Correct 116 ms 12448 KB Output is correct
15 Correct 77 ms 15700 KB Output is correct
16 Correct 62 ms 14524 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 156 ms 21144 KB Output is correct
23 Correct 143 ms 14800 KB Output is correct
24 Correct 102 ms 9576 KB Output is correct
25 Correct 138 ms 15224 KB Output is correct
26 Correct 87 ms 15680 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 5 ms 724 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 472 KB Output is correct
34 Correct 188 ms 21116 KB Output is correct
35 Correct 169 ms 14552 KB Output is correct
36 Correct 187 ms 15324 KB Output is correct
37 Correct 179 ms 15412 KB Output is correct
38 Correct 94 ms 15948 KB Output is correct
39 Correct 51 ms 8792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 130 ms 14352 KB Output is correct
12 Correct 80 ms 8192 KB Output is correct
13 Correct 95 ms 10304 KB Output is correct
14 Correct 116 ms 12448 KB Output is correct
15 Correct 77 ms 15700 KB Output is correct
16 Correct 62 ms 14524 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 156 ms 21144 KB Output is correct
23 Correct 143 ms 14800 KB Output is correct
24 Correct 102 ms 9576 KB Output is correct
25 Correct 138 ms 15224 KB Output is correct
26 Correct 87 ms 15680 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 5 ms 724 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 472 KB Output is correct
34 Correct 188 ms 21116 KB Output is correct
35 Correct 169 ms 14552 KB Output is correct
36 Correct 187 ms 15324 KB Output is correct
37 Correct 179 ms 15412 KB Output is correct
38 Correct 94 ms 15948 KB Output is correct
39 Correct 51 ms 8792 KB Output is correct
40 Correct 4 ms 852 KB Output is correct
41 Correct 6 ms 980 KB Output is correct
42 Correct 5 ms 728 KB Output is correct
43 Correct 4 ms 732 KB Output is correct
44 Correct 255 ms 22576 KB Output is correct
45 Correct 221 ms 16588 KB Output is correct
46 Correct 233 ms 16488 KB Output is correct
47 Correct 222 ms 16552 KB Output is correct
48 Correct 113 ms 16968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 416 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 12 ms 1440 KB Output is correct
27 Correct 9 ms 1240 KB Output is correct
28 Correct 7 ms 1100 KB Output is correct
29 Correct 6 ms 920 KB Output is correct
30 Correct 5 ms 896 KB Output is correct
31 Correct 6 ms 992 KB Output is correct
32 Correct 5 ms 724 KB Output is correct
33 Correct 4 ms 852 KB Output is correct
34 Correct 7 ms 1236 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 4 ms 824 KB Output is correct
38 Correct 4 ms 724 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 130 ms 14352 KB Output is correct
51 Correct 80 ms 8192 KB Output is correct
52 Correct 95 ms 10304 KB Output is correct
53 Correct 116 ms 12448 KB Output is correct
54 Correct 77 ms 15700 KB Output is correct
55 Correct 62 ms 14524 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 2 ms 596 KB Output is correct
61 Correct 156 ms 21144 KB Output is correct
62 Correct 143 ms 14800 KB Output is correct
63 Correct 102 ms 9576 KB Output is correct
64 Correct 138 ms 15224 KB Output is correct
65 Correct 87 ms 15680 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 5 ms 724 KB Output is correct
71 Correct 2 ms 464 KB Output is correct
72 Correct 2 ms 472 KB Output is correct
73 Correct 188 ms 21116 KB Output is correct
74 Correct 169 ms 14552 KB Output is correct
75 Correct 187 ms 15324 KB Output is correct
76 Correct 179 ms 15412 KB Output is correct
77 Correct 94 ms 15948 KB Output is correct
78 Correct 51 ms 8792 KB Output is correct
79 Correct 4 ms 852 KB Output is correct
80 Correct 6 ms 980 KB Output is correct
81 Correct 5 ms 728 KB Output is correct
82 Correct 4 ms 732 KB Output is correct
83 Correct 255 ms 22576 KB Output is correct
84 Correct 221 ms 16588 KB Output is correct
85 Correct 233 ms 16488 KB Output is correct
86 Correct 222 ms 16552 KB Output is correct
87 Correct 113 ms 16968 KB Output is correct
88 Correct 653 ms 52296 KB Output is correct
89 Correct 415 ms 31728 KB Output is correct
90 Correct 456 ms 40188 KB Output is correct
91 Correct 391 ms 25464 KB Output is correct
92 Correct 328 ms 22020 KB Output is correct
93 Correct 408 ms 31692 KB Output is correct
94 Correct 364 ms 24524 KB Output is correct
95 Correct 184 ms 20584 KB Output is correct
96 Correct 440 ms 40108 KB Output is correct
97 Correct 75 ms 17596 KB Output is correct
98 Correct 195 ms 20652 KB Output is correct
99 Correct 237 ms 20740 KB Output is correct