Submission #587811

# Submission time Handle Problem Language Result Execution time Memory
587811 2022-07-02T11:44:53 Z LastRonin Team Contest (JOI22_team) C++14
73 / 100
2000 ms 361536 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 = 150002;
const int M = 150002;
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, g2, g3;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		g.pb(a[i]);
		g2.pb(b[i]);
		g3.pb(c[i]);
	}
	sort(g.begin(), g.end());
	g.erase(unique(g.begin(), g.end()), g.end());
	sort(g2.begin(), g2.end());
	g2.erase(unique(g2.begin(), g2.end()), g2.end());
	sort(g3.begin(), g3.end());
	g3.erase(unique(g3.begin(), g3.end()), g3.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(g2.begin(), g2.end(), b[j]) - g2.begin() + 1;
		sc[j] = lower_bound(g3.begin(), g3.end(), c[j]) - g3.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);
		}
		sort(scan[i].begin(), scan[i].end(), comp1);
		for(auto u : scan[i]) {
			upd(sc[u], sb[u], Crt);	
			int gt2 = get(0, sc[u] - 1, Crt);
			if(gt2 > sb[u]) {
				upd2(gt2, sc[u], c[u] + g2[gt2 - 1], tdrt);			
			}
		}
		sort(scan[i].begin(), scan[i].end(), comp2);
		for(auto u : scan[i]) {
			upd(sb[u], sc[u], Brt);
			int gt = get(0, sb[u] - 1, Brt);
			if(gt > sc[u]) {
				upd2(sb[u], gt, b[u] + g3[gt - 1], tdrt);			
			}
		}
	}
	cout << sum;
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:119:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |  for(int i = 1; i <= g.size(); i++) {
      |                 ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3852 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 3 ms 3788 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 2 ms 3796 KB Output is correct
12 Correct 3 ms 3796 KB Output is correct
13 Correct 3 ms 3808 KB Output is correct
14 Correct 5 ms 4628 KB Output is correct
15 Correct 3 ms 4116 KB Output is correct
16 Correct 5 ms 4308 KB Output is correct
17 Correct 3 ms 4052 KB Output is correct
18 Correct 3 ms 4180 KB Output is correct
19 Correct 3 ms 4108 KB Output is correct
20 Correct 3 ms 3924 KB Output is correct
21 Correct 3 ms 3924 KB Output is correct
22 Correct 3 ms 3924 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 3 ms 3924 KB Output is correct
25 Correct 3 ms 3824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3852 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 3 ms 3788 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 2 ms 3796 KB Output is correct
12 Correct 3 ms 3796 KB Output is correct
13 Correct 3 ms 3808 KB Output is correct
14 Correct 5 ms 4628 KB Output is correct
15 Correct 3 ms 4116 KB Output is correct
16 Correct 5 ms 4308 KB Output is correct
17 Correct 3 ms 4052 KB Output is correct
18 Correct 3 ms 4180 KB Output is correct
19 Correct 3 ms 4108 KB Output is correct
20 Correct 3 ms 3924 KB Output is correct
21 Correct 3 ms 3924 KB Output is correct
22 Correct 3 ms 3924 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 3 ms 3924 KB Output is correct
25 Correct 3 ms 3824 KB Output is correct
26 Correct 49 ms 15380 KB Output is correct
27 Correct 27 ms 10540 KB Output is correct
28 Correct 25 ms 10620 KB Output is correct
29 Correct 14 ms 7636 KB Output is correct
30 Correct 14 ms 7764 KB Output is correct
31 Correct 22 ms 7316 KB Output is correct
32 Correct 12 ms 5460 KB Output is correct
33 Correct 7 ms 4252 KB Output is correct
34 Correct 9 ms 4760 KB Output is correct
35 Correct 3 ms 3924 KB Output is correct
36 Correct 3 ms 3988 KB Output is correct
37 Correct 7 ms 4308 KB Output is correct
38 Correct 7 ms 4308 KB Output is correct
39 Correct 9 ms 4056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 ms 3796 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3792 KB Output is correct
10 Correct 3 ms 3876 KB Output is correct
11 Correct 334 ms 10852 KB Output is correct
12 Correct 128 ms 8896 KB Output is correct
13 Correct 82 ms 9792 KB Output is correct
14 Correct 261 ms 11584 KB Output is correct
15 Correct 140 ms 11116 KB Output is correct
16 Correct 72 ms 11136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 ms 3796 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3792 KB Output is correct
10 Correct 3 ms 3876 KB Output is correct
11 Correct 334 ms 10852 KB Output is correct
12 Correct 128 ms 8896 KB Output is correct
13 Correct 82 ms 9792 KB Output is correct
14 Correct 261 ms 11584 KB Output is correct
15 Correct 140 ms 11116 KB Output is correct
16 Correct 72 ms 11136 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 3796 KB Output is correct
20 Correct 3 ms 3924 KB Output is correct
21 Correct 8 ms 4040 KB Output is correct
22 Correct 438 ms 10468 KB Output is correct
23 Correct 318 ms 10336 KB Output is correct
24 Correct 219 ms 8864 KB Output is correct
25 Correct 236 ms 10860 KB Output is correct
26 Correct 144 ms 11012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 ms 3796 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3792 KB Output is correct
10 Correct 3 ms 3876 KB Output is correct
11 Correct 334 ms 10852 KB Output is correct
12 Correct 128 ms 8896 KB Output is correct
13 Correct 82 ms 9792 KB Output is correct
14 Correct 261 ms 11584 KB Output is correct
15 Correct 140 ms 11116 KB Output is correct
16 Correct 72 ms 11136 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 3796 KB Output is correct
20 Correct 3 ms 3924 KB Output is correct
21 Correct 8 ms 4040 KB Output is correct
22 Correct 438 ms 10468 KB Output is correct
23 Correct 318 ms 10336 KB Output is correct
24 Correct 219 ms 8864 KB Output is correct
25 Correct 236 ms 10860 KB Output is correct
26 Correct 144 ms 11012 KB Output is correct
27 Correct 4 ms 4180 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
29 Correct 3 ms 3924 KB Output is correct
30 Correct 2 ms 3924 KB Output is correct
31 Correct 12 ms 5460 KB Output is correct
32 Correct 3 ms 3924 KB Output is correct
33 Correct 3 ms 3948 KB Output is correct
34 Correct 494 ms 11044 KB Output is correct
35 Correct 382 ms 14384 KB Output is correct
36 Correct 424 ms 15332 KB Output is correct
37 Correct 318 ms 16008 KB Output is correct
38 Correct 163 ms 10900 KB Output is correct
39 Correct 212 ms 8560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 ms 3796 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3792 KB Output is correct
10 Correct 3 ms 3876 KB Output is correct
11 Correct 334 ms 10852 KB Output is correct
12 Correct 128 ms 8896 KB Output is correct
13 Correct 82 ms 9792 KB Output is correct
14 Correct 261 ms 11584 KB Output is correct
15 Correct 140 ms 11116 KB Output is correct
16 Correct 72 ms 11136 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 3796 KB Output is correct
20 Correct 3 ms 3924 KB Output is correct
21 Correct 8 ms 4040 KB Output is correct
22 Correct 438 ms 10468 KB Output is correct
23 Correct 318 ms 10336 KB Output is correct
24 Correct 219 ms 8864 KB Output is correct
25 Correct 236 ms 10860 KB Output is correct
26 Correct 144 ms 11012 KB Output is correct
27 Correct 4 ms 4180 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
29 Correct 3 ms 3924 KB Output is correct
30 Correct 2 ms 3924 KB Output is correct
31 Correct 12 ms 5460 KB Output is correct
32 Correct 3 ms 3924 KB Output is correct
33 Correct 3 ms 3948 KB Output is correct
34 Correct 494 ms 11044 KB Output is correct
35 Correct 382 ms 14384 KB Output is correct
36 Correct 424 ms 15332 KB Output is correct
37 Correct 318 ms 16008 KB Output is correct
38 Correct 163 ms 10900 KB Output is correct
39 Correct 212 ms 8560 KB Output is correct
40 Correct 14 ms 7660 KB Output is correct
41 Correct 23 ms 7172 KB Output is correct
42 Correct 5 ms 4180 KB Output is correct
43 Correct 6 ms 4180 KB Output is correct
44 Correct 1072 ms 24076 KB Output is correct
45 Correct 694 ms 80004 KB Output is correct
46 Correct 694 ms 70948 KB Output is correct
47 Correct 563 ms 85548 KB Output is correct
48 Correct 173 ms 10932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3852 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 3 ms 3788 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 2 ms 3796 KB Output is correct
12 Correct 3 ms 3796 KB Output is correct
13 Correct 3 ms 3808 KB Output is correct
14 Correct 5 ms 4628 KB Output is correct
15 Correct 3 ms 4116 KB Output is correct
16 Correct 5 ms 4308 KB Output is correct
17 Correct 3 ms 4052 KB Output is correct
18 Correct 3 ms 4180 KB Output is correct
19 Correct 3 ms 4108 KB Output is correct
20 Correct 3 ms 3924 KB Output is correct
21 Correct 3 ms 3924 KB Output is correct
22 Correct 3 ms 3924 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 3 ms 3924 KB Output is correct
25 Correct 3 ms 3824 KB Output is correct
26 Correct 49 ms 15380 KB Output is correct
27 Correct 27 ms 10540 KB Output is correct
28 Correct 25 ms 10620 KB Output is correct
29 Correct 14 ms 7636 KB Output is correct
30 Correct 14 ms 7764 KB Output is correct
31 Correct 22 ms 7316 KB Output is correct
32 Correct 12 ms 5460 KB Output is correct
33 Correct 7 ms 4252 KB Output is correct
34 Correct 9 ms 4760 KB Output is correct
35 Correct 3 ms 3924 KB Output is correct
36 Correct 3 ms 3988 KB Output is correct
37 Correct 7 ms 4308 KB Output is correct
38 Correct 7 ms 4308 KB Output is correct
39 Correct 9 ms 4056 KB Output is correct
40 Correct 2 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 3 ms 3796 KB Output is correct
45 Correct 3 ms 3796 KB Output is correct
46 Correct 3 ms 3796 KB Output is correct
47 Correct 2 ms 3796 KB Output is correct
48 Correct 2 ms 3792 KB Output is correct
49 Correct 3 ms 3876 KB Output is correct
50 Correct 334 ms 10852 KB Output is correct
51 Correct 128 ms 8896 KB Output is correct
52 Correct 82 ms 9792 KB Output is correct
53 Correct 261 ms 11584 KB Output is correct
54 Correct 140 ms 11116 KB Output is correct
55 Correct 72 ms 11136 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 3796 KB Output is correct
59 Correct 3 ms 3924 KB Output is correct
60 Correct 8 ms 4040 KB Output is correct
61 Correct 438 ms 10468 KB Output is correct
62 Correct 318 ms 10336 KB Output is correct
63 Correct 219 ms 8864 KB Output is correct
64 Correct 236 ms 10860 KB Output is correct
65 Correct 144 ms 11012 KB Output is correct
66 Correct 4 ms 4180 KB Output is correct
67 Correct 3 ms 4052 KB Output is correct
68 Correct 3 ms 3924 KB Output is correct
69 Correct 2 ms 3924 KB Output is correct
70 Correct 12 ms 5460 KB Output is correct
71 Correct 3 ms 3924 KB Output is correct
72 Correct 3 ms 3948 KB Output is correct
73 Correct 494 ms 11044 KB Output is correct
74 Correct 382 ms 14384 KB Output is correct
75 Correct 424 ms 15332 KB Output is correct
76 Correct 318 ms 16008 KB Output is correct
77 Correct 163 ms 10900 KB Output is correct
78 Correct 212 ms 8560 KB Output is correct
79 Correct 14 ms 7660 KB Output is correct
80 Correct 23 ms 7172 KB Output is correct
81 Correct 5 ms 4180 KB Output is correct
82 Correct 6 ms 4180 KB Output is correct
83 Correct 1072 ms 24076 KB Output is correct
84 Correct 694 ms 80004 KB Output is correct
85 Correct 694 ms 70948 KB Output is correct
86 Correct 563 ms 85548 KB Output is correct
87 Correct 173 ms 10932 KB Output is correct
88 Execution timed out 2096 ms 361536 KB Time limit exceeded
89 Halted 0 ms 0 KB -