답안 #587794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587794 2022-07-02T11:25:16 Z LastRonin Team Contest (JOI22_team) C++14
73 / 100
2000 ms 499504 KB
#pragma GCC optimize("O3")

#include <bits/stdc++.h> 
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define pill pair<ll, ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

const int N = 2e5 + 1;
const int M = 5E5 + 1;
const ll hsh[2] = {1555555699, 1222222763};
const ll P = 113;

int n;    
int a[N], b[N], c[N];
int sa[N], sb[N], sc[N];


struct node {
	node *l = nullptr, *r = nullptr;
	int val = 0;
} *Brt = new node(), *Crt = new node();

struct tdnode {
	tdnode *l = nullptr, *r = nullptr;
	node *val = nullptr;
	tdnode() {
		val = new node();
	}
} *tdrt = new tdnode();

vector<ll> scan[M];

void upd(int p, int z, node *v, int tl = 0, int tr = M + 1) {
	if(tl == tr) {
		v->val = max(v->val, z);
		return;
	}
	ll m = (tl + tr) >> 1ll;
	if(p <= m) {
		if(!v->l)v->l = new node();
		upd(p, z, v->l, tl, m);
	} else {
		if(!v->r)v->r = new node();
		upd(p, z, v->r, m + 1, tr);
	}
	v->val = max(v->val, z);
}
int get(int l, int r, node *v, int tl = 0, int tr = M + 1) {
	if(l > tr || tl > r || !v) 
		return 0;
	if(l <= tl && tr <= r) 
		return v->val;
	ll m = (tl + tr) >> 1ll;
	return max(get(l, r, v->l, tl, m), get(l, r, v->r, m + 1, tr));
}

void upd2(int x, int y, int z, tdnode *v, int tl = 0, int tr = M + 1) {
	if(tl == tr) {
		upd(y, z, v->val);
		return;
	}
	ll m = (tl + tr) >> 1ll;
	if(x <= m) {
		if(!v->l)v->l = new tdnode();
		upd2(x, y, z, v->l, tl, m);
	} else {
		if(!v->r)v->r = new tdnode();
		upd2(x, y, z, v->r, m + 1, tr);
	}
	upd(y, z, v->val);
}

int get2(int lx, int rx, int ly, int ry, tdnode *v, int tl = 0, int  tr = M + 1) {
	if(lx > tr || rx < tl || !v)return 0;
	if(lx <= tl && tr <= rx) {
		return get(ly, ry, v->val);
	}
	ll m = (tl + tr) >> 1ll;
	return max(get2(lx, rx, ly, ry, v->l, tl , m), get2(lx, rx, ly, ry, v->r, m + 1, tr));
}


bool comp2(int i, int j) {
	return b[i] < b[j];
}

bool comp1(int i, int j) {
	return c[i] < c[j];
}

int main() {
	speed;
	cin >> n;
	vector<int> g;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		g.pb(a[i]);
		g.pb(b[i]);
		g.pb(c[i]);
	}
	sort(g.begin(), g.end());
	g.erase(unique(g.begin(), g.end()), g.end());
	for(int j = 1; j <= n; j++) {
		sa[j] = lower_bound(g.begin(), g.end(), a[j]) - g.begin() + 1;
		sb[j] = lower_bound(g.begin(), g.end(), b[j]) - g.begin() + 1;
		sc[j] = lower_bound(g.begin(), g.end(), c[j]) - g.begin() + 1;
		scan[sa[j]].pb(j);		
	}
	int sum = -1;
	for(int i = 1; i <= g.size(); i++) {
		for(auto u : scan[i]) {
			int z = get2(sb[u] + 1, M, sc[u] + 1, M, tdrt);		
			if(z)sum = max(sum, a[u] + z);
		}
		vector<pair<int, int>> aa;
		sort(scan[i].begin(), scan[i].end(), comp1);
		for(auto u : scan[i]) {
			upd(sc[u], b[u], Crt);	
			int gt2 = get(0, sc[u] - 1, Crt);
			if(gt2 > b[u])aa.pb(mp(gt2, c[u]));								
		}
		sort(scan[i].begin(), scan[i].end(), comp2);
		for(auto u : scan[i]) {
			upd(sb[u], c[u], Brt);
			int gt = get(0, sb[u] - 1, Brt);
			if(gt > c[u])aa.pb(mp(b[u], gt));
		}
		for(auto u : aa) {
			int szha = lower_bound(g.begin(), g.end(), u.f) - g.begin() + 1;
			int szhb = lower_bound(g.begin(), g.end(), u.s) - g.begin() + 1;
			upd2(szha, szhb, u.f + u.s, tdrt);
		}
	}
	cout << sum;
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:115:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |  for(int i = 1; i <= g.size(); i++) {
      |                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 12060 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 6 ms 12040 KB Output is correct
7 Correct 7 ms 11988 KB Output is correct
8 Correct 7 ms 12036 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 12096 KB Output is correct
11 Correct 7 ms 11988 KB Output is correct
12 Correct 7 ms 11988 KB Output is correct
13 Correct 8 ms 11988 KB Output is correct
14 Correct 10 ms 13396 KB Output is correct
15 Correct 9 ms 12500 KB Output is correct
16 Correct 9 ms 12720 KB Output is correct
17 Correct 10 ms 12436 KB Output is correct
18 Correct 12 ms 12588 KB Output is correct
19 Correct 8 ms 12244 KB Output is correct
20 Correct 8 ms 12076 KB Output is correct
21 Correct 7 ms 12084 KB Output is correct
22 Correct 7 ms 12116 KB Output is correct
23 Correct 7 ms 12080 KB Output is correct
24 Correct 7 ms 12116 KB Output is correct
25 Correct 7 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 12060 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 6 ms 12040 KB Output is correct
7 Correct 7 ms 11988 KB Output is correct
8 Correct 7 ms 12036 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 12096 KB Output is correct
11 Correct 7 ms 11988 KB Output is correct
12 Correct 7 ms 11988 KB Output is correct
13 Correct 8 ms 11988 KB Output is correct
14 Correct 10 ms 13396 KB Output is correct
15 Correct 9 ms 12500 KB Output is correct
16 Correct 9 ms 12720 KB Output is correct
17 Correct 10 ms 12436 KB Output is correct
18 Correct 12 ms 12588 KB Output is correct
19 Correct 8 ms 12244 KB Output is correct
20 Correct 8 ms 12076 KB Output is correct
21 Correct 7 ms 12084 KB Output is correct
22 Correct 7 ms 12116 KB Output is correct
23 Correct 7 ms 12080 KB Output is correct
24 Correct 7 ms 12116 KB Output is correct
25 Correct 7 ms 12116 KB Output is correct
26 Correct 56 ms 31608 KB Output is correct
27 Correct 41 ms 23268 KB Output is correct
28 Correct 38 ms 22692 KB Output is correct
29 Correct 24 ms 17956 KB Output is correct
30 Correct 22 ms 16876 KB Output is correct
31 Correct 29 ms 15948 KB Output is correct
32 Correct 18 ms 13780 KB Output is correct
33 Correct 12 ms 12624 KB Output is correct
34 Correct 13 ms 13256 KB Output is correct
35 Correct 8 ms 12116 KB Output is correct
36 Correct 8 ms 12108 KB Output is correct
37 Correct 10 ms 12472 KB Output is correct
38 Correct 12 ms 12500 KB Output is correct
39 Correct 14 ms 12216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12116 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 8 ms 12116 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 11996 KB Output is correct
8 Correct 6 ms 12116 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 327 ms 19456 KB Output is correct
12 Correct 158 ms 17040 KB Output is correct
13 Correct 85 ms 18008 KB Output is correct
14 Correct 234 ms 20144 KB Output is correct
15 Correct 175 ms 20560 KB Output is correct
16 Correct 78 ms 20156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12116 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 8 ms 12116 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 11996 KB Output is correct
8 Correct 6 ms 12116 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 327 ms 19456 KB Output is correct
12 Correct 158 ms 17040 KB Output is correct
13 Correct 85 ms 18008 KB Output is correct
14 Correct 234 ms 20144 KB Output is correct
15 Correct 175 ms 20560 KB Output is correct
16 Correct 78 ms 20156 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 6 ms 11988 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 12172 KB Output is correct
21 Correct 13 ms 12184 KB Output is correct
22 Correct 453 ms 18852 KB Output is correct
23 Correct 371 ms 19040 KB Output is correct
24 Correct 229 ms 17420 KB Output is correct
25 Correct 304 ms 19436 KB Output is correct
26 Correct 164 ms 20348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12116 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 8 ms 12116 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 11996 KB Output is correct
8 Correct 6 ms 12116 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 327 ms 19456 KB Output is correct
12 Correct 158 ms 17040 KB Output is correct
13 Correct 85 ms 18008 KB Output is correct
14 Correct 234 ms 20144 KB Output is correct
15 Correct 175 ms 20560 KB Output is correct
16 Correct 78 ms 20156 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 6 ms 11988 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 12172 KB Output is correct
21 Correct 13 ms 12184 KB Output is correct
22 Correct 453 ms 18852 KB Output is correct
23 Correct 371 ms 19040 KB Output is correct
24 Correct 229 ms 17420 KB Output is correct
25 Correct 304 ms 19436 KB Output is correct
26 Correct 164 ms 20348 KB Output is correct
27 Correct 9 ms 12500 KB Output is correct
28 Correct 9 ms 12236 KB Output is correct
29 Correct 8 ms 12072 KB Output is correct
30 Correct 7 ms 12116 KB Output is correct
31 Correct 19 ms 13744 KB Output is correct
32 Correct 8 ms 12212 KB Output is correct
33 Correct 8 ms 12116 KB Output is correct
34 Correct 577 ms 19456 KB Output is correct
35 Correct 458 ms 22840 KB Output is correct
36 Correct 524 ms 23660 KB Output is correct
37 Correct 350 ms 24536 KB Output is correct
38 Correct 228 ms 20524 KB Output is correct
39 Correct 277 ms 20032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12116 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 8 ms 12116 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 11996 KB Output is correct
8 Correct 6 ms 12116 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 327 ms 19456 KB Output is correct
12 Correct 158 ms 17040 KB Output is correct
13 Correct 85 ms 18008 KB Output is correct
14 Correct 234 ms 20144 KB Output is correct
15 Correct 175 ms 20560 KB Output is correct
16 Correct 78 ms 20156 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 6 ms 11988 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 12172 KB Output is correct
21 Correct 13 ms 12184 KB Output is correct
22 Correct 453 ms 18852 KB Output is correct
23 Correct 371 ms 19040 KB Output is correct
24 Correct 229 ms 17420 KB Output is correct
25 Correct 304 ms 19436 KB Output is correct
26 Correct 164 ms 20348 KB Output is correct
27 Correct 9 ms 12500 KB Output is correct
28 Correct 9 ms 12236 KB Output is correct
29 Correct 8 ms 12072 KB Output is correct
30 Correct 7 ms 12116 KB Output is correct
31 Correct 19 ms 13744 KB Output is correct
32 Correct 8 ms 12212 KB Output is correct
33 Correct 8 ms 12116 KB Output is correct
34 Correct 577 ms 19456 KB Output is correct
35 Correct 458 ms 22840 KB Output is correct
36 Correct 524 ms 23660 KB Output is correct
37 Correct 350 ms 24536 KB Output is correct
38 Correct 228 ms 20524 KB Output is correct
39 Correct 277 ms 20032 KB Output is correct
40 Correct 22 ms 16948 KB Output is correct
41 Correct 31 ms 15860 KB Output is correct
42 Correct 11 ms 12500 KB Output is correct
43 Correct 12 ms 12500 KB Output is correct
44 Correct 1182 ms 34028 KB Output is correct
45 Correct 711 ms 88504 KB Output is correct
46 Correct 819 ms 79832 KB Output is correct
47 Correct 613 ms 94116 KB Output is correct
48 Correct 196 ms 20808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 8 ms 12116 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 12060 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 6 ms 12040 KB Output is correct
7 Correct 7 ms 11988 KB Output is correct
8 Correct 7 ms 12036 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 12096 KB Output is correct
11 Correct 7 ms 11988 KB Output is correct
12 Correct 7 ms 11988 KB Output is correct
13 Correct 8 ms 11988 KB Output is correct
14 Correct 10 ms 13396 KB Output is correct
15 Correct 9 ms 12500 KB Output is correct
16 Correct 9 ms 12720 KB Output is correct
17 Correct 10 ms 12436 KB Output is correct
18 Correct 12 ms 12588 KB Output is correct
19 Correct 8 ms 12244 KB Output is correct
20 Correct 8 ms 12076 KB Output is correct
21 Correct 7 ms 12084 KB Output is correct
22 Correct 7 ms 12116 KB Output is correct
23 Correct 7 ms 12080 KB Output is correct
24 Correct 7 ms 12116 KB Output is correct
25 Correct 7 ms 12116 KB Output is correct
26 Correct 56 ms 31608 KB Output is correct
27 Correct 41 ms 23268 KB Output is correct
28 Correct 38 ms 22692 KB Output is correct
29 Correct 24 ms 17956 KB Output is correct
30 Correct 22 ms 16876 KB Output is correct
31 Correct 29 ms 15948 KB Output is correct
32 Correct 18 ms 13780 KB Output is correct
33 Correct 12 ms 12624 KB Output is correct
34 Correct 13 ms 13256 KB Output is correct
35 Correct 8 ms 12116 KB Output is correct
36 Correct 8 ms 12108 KB Output is correct
37 Correct 10 ms 12472 KB Output is correct
38 Correct 12 ms 12500 KB Output is correct
39 Correct 14 ms 12216 KB Output is correct
40 Correct 7 ms 12116 KB Output is correct
41 Correct 8 ms 12116 KB Output is correct
42 Correct 7 ms 11988 KB Output is correct
43 Correct 8 ms 12116 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 7 ms 11988 KB Output is correct
46 Correct 7 ms 11996 KB Output is correct
47 Correct 6 ms 12116 KB Output is correct
48 Correct 7 ms 11988 KB Output is correct
49 Correct 7 ms 11988 KB Output is correct
50 Correct 327 ms 19456 KB Output is correct
51 Correct 158 ms 17040 KB Output is correct
52 Correct 85 ms 18008 KB Output is correct
53 Correct 234 ms 20144 KB Output is correct
54 Correct 175 ms 20560 KB Output is correct
55 Correct 78 ms 20156 KB Output is correct
56 Correct 7 ms 11988 KB Output is correct
57 Correct 6 ms 11988 KB Output is correct
58 Correct 7 ms 11988 KB Output is correct
59 Correct 7 ms 12172 KB Output is correct
60 Correct 13 ms 12184 KB Output is correct
61 Correct 453 ms 18852 KB Output is correct
62 Correct 371 ms 19040 KB Output is correct
63 Correct 229 ms 17420 KB Output is correct
64 Correct 304 ms 19436 KB Output is correct
65 Correct 164 ms 20348 KB Output is correct
66 Correct 9 ms 12500 KB Output is correct
67 Correct 9 ms 12236 KB Output is correct
68 Correct 8 ms 12072 KB Output is correct
69 Correct 7 ms 12116 KB Output is correct
70 Correct 19 ms 13744 KB Output is correct
71 Correct 8 ms 12212 KB Output is correct
72 Correct 8 ms 12116 KB Output is correct
73 Correct 577 ms 19456 KB Output is correct
74 Correct 458 ms 22840 KB Output is correct
75 Correct 524 ms 23660 KB Output is correct
76 Correct 350 ms 24536 KB Output is correct
77 Correct 228 ms 20524 KB Output is correct
78 Correct 277 ms 20032 KB Output is correct
79 Correct 22 ms 16948 KB Output is correct
80 Correct 31 ms 15860 KB Output is correct
81 Correct 11 ms 12500 KB Output is correct
82 Correct 12 ms 12500 KB Output is correct
83 Correct 1182 ms 34028 KB Output is correct
84 Correct 711 ms 88504 KB Output is correct
85 Correct 819 ms 79832 KB Output is correct
86 Correct 613 ms 94116 KB Output is correct
87 Correct 196 ms 20808 KB Output is correct
88 Execution timed out 2061 ms 499504 KB Time limit exceeded
89 Halted 0 ms 0 KB -