답안 #587912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587912 2022-07-02T13:54:38 Z LastRonin Team Contest (JOI22_team) C++14
100 / 100
742 ms 141564 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;

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

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];
 
 
vector<int> g, g2, g3;
 
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));
}
 
struct seg {
    node *t[4 * N];
    void build(int v = 1, int tl = 0, int tr = g2.size()) {
    	if(tl == tr) {
    		t[v] = new node();
    		return;
    	}
    	int m = (tl + tr) >> 1;
    	build(v * 2, tl, m);
    	build(v * 2 + 1, m + 1, tr);
    	t[v] = new node();
    }
	void upd2(int x, int y, int z, int v = 1, int tl = 0, int tr = g2.size()) {
		if(tl == tr) {
			upd(y, z, t[v]);
			return;
		}
		ll m = (tl + tr) >> 1ll;
		if(x <= m) {
			upd2(x, y, z, v * 2, tl, m);
		} else {
			upd2(x, y, z, v * 2 + 1, m + 1, tr);
		}
		upd(y, z, t[v]);
	} 
	int get2(int lx, int rx, int ly, int ry, int v = 1, int tl = 0, int  tr = g2.size()) {
		if(lx > tr || rx < tl || !t[v])return 0;
		if(lx <= tl && tr <= rx) {
			return get(ly, ry, t[v]);
		}
		ll m = (tl + tr) >> 1ll;
		return max(get2(lx, rx, ly, ry, v * 2, tl , m), get2(lx, rx, ly, ry, v * 2 + 1, m + 1, tr));
	}
} rot; 
 
bool comp2(int i, int j) {
	return b[i] < b[j];
}
 
bool comp1(int i, int j) {
	return c[i] < c[j];
}
ll z[N];
 
int main() {
	speed;
	cin >> n;
	for(int i = 1; i <= n; i++)
		z[i] = i;
	shuffle(z + 1, z + n + 1, bruh);
	for(int i = 1; i <= n; i++) {
		ll x = z[i];
		cin >> a[x] >> b[x] >> c[x];
		g.pb(a[x]);
		g2.pb(b[x]);
		g3.pb(c[x]);
	}
	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);		
	}
	rot.build();
	int sum = -1;
	for(int i = 1; i <= g.size(); i++) {
		for(auto u : scan[i]) {
			int z = rot.get2(sb[u] + 1, g2.size(), sc[u] + 1, g3.size());		
			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] && rot.get2(gt2, g2.size(), sc[u], g3.size()) < c[u] + g2[gt2 - 1]) {
				rot.upd2(gt2, sc[u], c[u] + g2[gt2 - 1]);			
			}
		}
		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] && rot.get2(sb[u], g2.size(), gt, g3.size()) < b[u] + g3[gt - 1]) {
				rot.upd2(sb[u], gt, b[u] + g3[gt - 1]);			
			}
		}
	}
	cout << sum;
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:137:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |  for(int i = 1; i <= g.size(); i++) {
      |                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3796 KB Output is correct
2 Correct 3 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 2 ms 3796 KB Output is correct
7 Correct 2 ms 3808 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 2 ms 3816 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 3924 KB Output is correct
15 Correct 3 ms 3924 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4052 KB Output is correct
18 Correct 3 ms 3924 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 4 ms 3924 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 2 ms 3924 KB Output is correct
25 Correct 2 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3796 KB Output is correct
2 Correct 3 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 2 ms 3796 KB Output is correct
7 Correct 2 ms 3808 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 2 ms 3816 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 3924 KB Output is correct
15 Correct 3 ms 3924 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4052 KB Output is correct
18 Correct 3 ms 3924 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 4 ms 3924 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 2 ms 3924 KB Output is correct
25 Correct 2 ms 3924 KB Output is correct
26 Correct 11 ms 5048 KB Output is correct
27 Correct 13 ms 5252 KB Output is correct
28 Correct 13 ms 5732 KB Output is correct
29 Correct 12 ms 6868 KB Output is correct
30 Correct 9 ms 5556 KB Output is correct
31 Correct 13 ms 4692 KB Output is correct
32 Correct 11 ms 4664 KB Output is correct
33 Correct 8 ms 4276 KB Output is correct
34 Correct 10 ms 4948 KB Output is correct
35 Correct 3 ms 3924 KB Output is correct
36 Correct 3 ms 3924 KB Output is correct
37 Correct 6 ms 4308 KB Output is correct
38 Correct 7 ms 4420 KB Output is correct
39 Correct 5 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 3 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 130 ms 11816 KB Output is correct
12 Correct 69 ms 9536 KB Output is correct
13 Correct 72 ms 10468 KB Output is correct
14 Correct 116 ms 12672 KB Output is correct
15 Correct 94 ms 12212 KB Output is correct
16 Correct 76 ms 12292 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 3 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 130 ms 11816 KB Output is correct
12 Correct 69 ms 9536 KB Output is correct
13 Correct 72 ms 10468 KB Output is correct
14 Correct 116 ms 12672 KB Output is correct
15 Correct 94 ms 12212 KB Output is correct
16 Correct 76 ms 12292 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 3796 KB Output is correct
21 Correct 6 ms 3924 KB Output is correct
22 Correct 175 ms 11772 KB Output is correct
23 Correct 143 ms 11608 KB Output is correct
24 Correct 100 ms 9596 KB Output is correct
25 Correct 141 ms 12088 KB Output is correct
26 Correct 92 ms 12176 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 3 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 130 ms 11816 KB Output is correct
12 Correct 69 ms 9536 KB Output is correct
13 Correct 72 ms 10468 KB Output is correct
14 Correct 116 ms 12672 KB Output is correct
15 Correct 94 ms 12212 KB Output is correct
16 Correct 76 ms 12292 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 3796 KB Output is correct
21 Correct 6 ms 3924 KB Output is correct
22 Correct 175 ms 11772 KB Output is correct
23 Correct 143 ms 11608 KB Output is correct
24 Correct 100 ms 9596 KB Output is correct
25 Correct 141 ms 12088 KB Output is correct
26 Correct 92 ms 12176 KB Output is correct
27 Correct 3 ms 3924 KB Output is correct
28 Correct 3 ms 3924 KB Output is correct
29 Correct 3 ms 3924 KB Output is correct
30 Correct 3 ms 3924 KB Output is correct
31 Correct 9 ms 4692 KB Output is correct
32 Correct 3 ms 3924 KB Output is correct
33 Correct 4 ms 3924 KB Output is correct
34 Correct 275 ms 11468 KB Output is correct
35 Correct 193 ms 13260 KB Output is correct
36 Correct 238 ms 14024 KB Output is correct
37 Correct 179 ms 14432 KB Output is correct
38 Correct 104 ms 12104 KB Output is correct
39 Correct 108 ms 8612 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 3 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 130 ms 11816 KB Output is correct
12 Correct 69 ms 9536 KB Output is correct
13 Correct 72 ms 10468 KB Output is correct
14 Correct 116 ms 12672 KB Output is correct
15 Correct 94 ms 12212 KB Output is correct
16 Correct 76 ms 12292 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 3796 KB Output is correct
21 Correct 6 ms 3924 KB Output is correct
22 Correct 175 ms 11772 KB Output is correct
23 Correct 143 ms 11608 KB Output is correct
24 Correct 100 ms 9596 KB Output is correct
25 Correct 141 ms 12088 KB Output is correct
26 Correct 92 ms 12176 KB Output is correct
27 Correct 3 ms 3924 KB Output is correct
28 Correct 3 ms 3924 KB Output is correct
29 Correct 3 ms 3924 KB Output is correct
30 Correct 3 ms 3924 KB Output is correct
31 Correct 9 ms 4692 KB Output is correct
32 Correct 3 ms 3924 KB Output is correct
33 Correct 4 ms 3924 KB Output is correct
34 Correct 275 ms 11468 KB Output is correct
35 Correct 193 ms 13260 KB Output is correct
36 Correct 238 ms 14024 KB Output is correct
37 Correct 179 ms 14432 KB Output is correct
38 Correct 104 ms 12104 KB Output is correct
39 Correct 108 ms 8612 KB Output is correct
40 Correct 12 ms 5504 KB Output is correct
41 Correct 12 ms 4752 KB Output is correct
42 Correct 6 ms 4308 KB Output is correct
43 Correct 7 ms 4396 KB Output is correct
44 Correct 306 ms 13188 KB Output is correct
45 Correct 336 ms 44352 KB Output is correct
46 Correct 348 ms 40880 KB Output is correct
47 Correct 332 ms 48900 KB Output is correct
48 Correct 155 ms 12288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3796 KB Output is correct
2 Correct 3 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 2 ms 3796 KB Output is correct
7 Correct 2 ms 3808 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 2 ms 3816 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 3924 KB Output is correct
15 Correct 3 ms 3924 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4052 KB Output is correct
18 Correct 3 ms 3924 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 4 ms 3924 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 2 ms 3924 KB Output is correct
25 Correct 2 ms 3924 KB Output is correct
26 Correct 11 ms 5048 KB Output is correct
27 Correct 13 ms 5252 KB Output is correct
28 Correct 13 ms 5732 KB Output is correct
29 Correct 12 ms 6868 KB Output is correct
30 Correct 9 ms 5556 KB Output is correct
31 Correct 13 ms 4692 KB Output is correct
32 Correct 11 ms 4664 KB Output is correct
33 Correct 8 ms 4276 KB Output is correct
34 Correct 10 ms 4948 KB Output is correct
35 Correct 3 ms 3924 KB Output is correct
36 Correct 3 ms 3924 KB Output is correct
37 Correct 6 ms 4308 KB Output is correct
38 Correct 7 ms 4420 KB Output is correct
39 Correct 5 ms 3924 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 2 ms 3796 KB Output is correct
45 Correct 2 ms 3796 KB Output is correct
46 Correct 3 ms 3796 KB Output is correct
47 Correct 3 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 130 ms 11816 KB Output is correct
51 Correct 69 ms 9536 KB Output is correct
52 Correct 72 ms 10468 KB Output is correct
53 Correct 116 ms 12672 KB Output is correct
54 Correct 94 ms 12212 KB Output is correct
55 Correct 76 ms 12292 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 3796 KB Output is correct
60 Correct 6 ms 3924 KB Output is correct
61 Correct 175 ms 11772 KB Output is correct
62 Correct 143 ms 11608 KB Output is correct
63 Correct 100 ms 9596 KB Output is correct
64 Correct 141 ms 12088 KB Output is correct
65 Correct 92 ms 12176 KB Output is correct
66 Correct 3 ms 3924 KB Output is correct
67 Correct 3 ms 3924 KB Output is correct
68 Correct 3 ms 3924 KB Output is correct
69 Correct 3 ms 3924 KB Output is correct
70 Correct 9 ms 4692 KB Output is correct
71 Correct 3 ms 3924 KB Output is correct
72 Correct 4 ms 3924 KB Output is correct
73 Correct 275 ms 11468 KB Output is correct
74 Correct 193 ms 13260 KB Output is correct
75 Correct 238 ms 14024 KB Output is correct
76 Correct 179 ms 14432 KB Output is correct
77 Correct 104 ms 12104 KB Output is correct
78 Correct 108 ms 8612 KB Output is correct
79 Correct 12 ms 5504 KB Output is correct
80 Correct 12 ms 4752 KB Output is correct
81 Correct 6 ms 4308 KB Output is correct
82 Correct 7 ms 4396 KB Output is correct
83 Correct 306 ms 13188 KB Output is correct
84 Correct 336 ms 44352 KB Output is correct
85 Correct 348 ms 40880 KB Output is correct
86 Correct 332 ms 48900 KB Output is correct
87 Correct 155 ms 12288 KB Output is correct
88 Correct 645 ms 47332 KB Output is correct
89 Correct 580 ms 100396 KB Output is correct
90 Correct 638 ms 43192 KB Output is correct
91 Correct 655 ms 141564 KB Output is correct
92 Correct 471 ms 46988 KB Output is correct
93 Correct 742 ms 133320 KB Output is correct
94 Correct 689 ms 124444 KB Output is correct
95 Correct 168 ms 20448 KB Output is correct
96 Correct 347 ms 47188 KB Output is correct
97 Correct 103 ms 12216 KB Output is correct
98 Correct 233 ms 23004 KB Output is correct
99 Correct 390 ms 23076 KB Output is correct