Submission #549430

# Submission time Handle Problem Language Result Execution time Memory
549430 2022-04-15T19:42:53 Z keta_tsimakuridze Team Contest (JOI22_team) C++14
100 / 100
1638 ms 271120 KB
#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"

const int N = 5e5 + 5, mod = 1e9 + 7, inf = 1e9; //!
int t, tree[4 * N][2], cur, val[N], rr2[N][2];
pair<int,pii> p[N];
set<pii> s[4 * N][2];
void upd(int u, int id, int l,int r,int t,int val) {
	if(l > id || r < id) return;
	if(l == r) {
		tree[u][t] = max(tree[u][t], val);
		return;
	}
	int mid = (l + r) / 2;
	upd(2 * u, id, l, mid, t, val); upd(2 * u + 1, id, mid + 1,r, t, val);
	for(int k = 0; k < 2; k++) tree[u][k] = max(tree[2 * u][k], tree[2 * u + 1][k]);
}
int get(int u,int st,int en,int l,int r,int t) {
	if(l > en || r < st) return 0;
	if(st <= l && r <= en) return tree[u][t];
	int mid = (l + r) / 2;
	return max(get(2 * u, st, en, l, mid, t), get(2 * u + 1, st, en, mid + 1, r, t));
}

void updSum(int u,int id, int l,int r, int t, int val1, int val2) {
	if(l > id || r < id) return;
	int f = 0;
	if(s[u][t].size() && s[u][t].upper_bound({val1, 0}) != s[u][t].end() ) {
		if((*s[u][t].upper_bound({val1, 0})).s >= val1 + val2)f = 1;
		else 			
		if((*s[u][t].upper_bound({val1, 0})).f == val1) {
				s[u][t].erase((*s[u][t].upper_bound({val1, 0})));
		}
	}
	if(!f) s[u][t].insert({val1, val2 + val1});
	while(!f && s[u][t].size() && s[u][t].upper_bound({val1 - 1, inf}) != s[u][t].begin()) {
		pii p = *--s[u][t].upper_bound({val1 - 1, inf});
		if(p.s > val1 + val2) break;
		s[u][t].erase(p);
	}
	for(set<pii> :: iterator it = s[u][t].begin(); it != s[u][t].end(); it++) {
		if((*it).f < val1 && (*it).s <= val1 + val2) {
			s[u][t].erase(*it);
			it--;
		}
	}
	if(l == r) return;
	int mid = (l + r) / 2;
	updSum(2 * u, id, l, mid, t, val1, val2); updSum(2 * u + 1, id, mid + 1,r, t, val1, val2);
}
int getSum(int u,int st, int en, int l,int r,int t,int val1) {
	if(l > en || r < st) return -inf;
	if(st <= l && r <= en) {
		if(s[u][t].upper_bound({val1 + 1, 0}) == s[u][t].end()) return -inf;
		return (*s[u][t].upper_bound({val1 + 1, 0})).s;
	}
	int mid = (l + r) / 2;
	return max(getSum(2 * u, st, en, l, mid, t, val1), getSum(2 * u + 1, st, en, mid + 1, r, t, val1));
}
void add(pair<int, pii> p) {
	int a = p.s.f, b = p.s.s;
	int mxa = get(1, 1, a - 1, 1, cur, 0); 
	int mxb = get(1, 1, b - 1, 1, cur, 1); 
	upd(1, a, 1, cur, 0, b);
	upd(1, b, 1, cur, 1, a);
	if(mxa <= b) mxa = 0; if(mxb <= a) mxb = 0;
//	rr2[a][0] = max(rr2[a][0], mxa);
//	rr2[b][1] = max(rr2[b][1], mxb);
	if(mxa)
	updSum(1, a, 1, cur, 0, val[mxa], val[a]); 
	if(mxb)
	updSum(1, b, 1, cur, 1, val[mxb], val[b]);
}
int getSum2(int u,int st, int en, int l,int r,int t,int val1) {
	int ans = -inf;
	for(int i = st; i <= en; i++) {
		if(val1 < val[rr2[i][t]]) 
		ans = max(ans, val[rr2[i][t]] + val[i]);
	}
	return ans;
}
main() {
	ios_base::sync_with_stdio(false),
	cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	vector<int> x;
	map<int,int> id;
	for(int i = 1; i <= n; i++) {
		cin >> p[i].f >> p[i].s.f >> p[i].s.s;
		x.push_back(p[i].f); x.push_back(p[i].s.f); x.push_back(p[i].s.s);
	}
	sort(x.begin(),x.end());
	cur = 0;
	for(int i = 0; i < x.size(); i++) {
		if(!i || x[i] != x[i - 1]) ++cur;
		id[x[i]] = cur;
		val[cur] = x[i];
	}
	for(int i = 1; i <= n; i++) {
		p[i].f = id[p[i].f];
		p[i].s.f = id[p[i].s.f];
		p[i].s.s = id[p[i].s.s];
	}
	val[0] = -inf;
	sort(p + 1, p + n + 1);
	int last = 0, ans = -inf;
	for(int i = 1; i <= n; i++) {
		
		int x = 0;
		
		x = max(getSum(1, p[i].s.s + 1, cur, 1, cur, 1, val[p[i].s.f]), getSum(1, p[i].s.f + 1, cur, 1, cur, 0, val[p[i].s.s]));
		ans = max(ans, x + val[p[i].f]);
		if(p[i].f != p[i + 1].f) {
			for(int j = last + 1; j <= i; j++) {

				add(p[j]);
			}
			last = i;
		}
	}
	ans = max(ans, -1);
	cout << ans;
}

Compilation message

team.cpp: In function 'void add(std::pair<int, std::pair<int, int> >)':
team.cpp:71:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   71 |  if(mxa <= b) mxa = 0; if(mxb <= a) mxb = 0;
      |  ^~
team.cpp:71:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   71 |  if(mxa <= b) mxa = 0; if(mxb <= a) mxb = 0;
      |                        ^~
team.cpp: At global scope:
team.cpp:87:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   87 | main() {
      | ^~~~
team.cpp: In function 'int main()':
team.cpp:100:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |  for(int i = 0; i < x.size(); i++) {
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 86 ms 188164 KB Output is correct
2 Correct 86 ms 188164 KB Output is correct
3 Correct 84 ms 188080 KB Output is correct
4 Correct 92 ms 188188 KB Output is correct
5 Correct 89 ms 188104 KB Output is correct
6 Correct 84 ms 188148 KB Output is correct
7 Correct 87 ms 188280 KB Output is correct
8 Correct 84 ms 188192 KB Output is correct
9 Correct 95 ms 188196 KB Output is correct
10 Correct 100 ms 188128 KB Output is correct
11 Correct 84 ms 188104 KB Output is correct
12 Correct 85 ms 188256 KB Output is correct
13 Correct 91 ms 188200 KB Output is correct
14 Correct 90 ms 188360 KB Output is correct
15 Correct 85 ms 188204 KB Output is correct
16 Correct 86 ms 188240 KB Output is correct
17 Correct 98 ms 188236 KB Output is correct
18 Correct 94 ms 188184 KB Output is correct
19 Correct 89 ms 188196 KB Output is correct
20 Correct 86 ms 188108 KB Output is correct
21 Correct 85 ms 188204 KB Output is correct
22 Correct 88 ms 188336 KB Output is correct
23 Correct 89 ms 188116 KB Output is correct
24 Correct 91 ms 188172 KB Output is correct
25 Correct 88 ms 188120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 188164 KB Output is correct
2 Correct 86 ms 188164 KB Output is correct
3 Correct 84 ms 188080 KB Output is correct
4 Correct 92 ms 188188 KB Output is correct
5 Correct 89 ms 188104 KB Output is correct
6 Correct 84 ms 188148 KB Output is correct
7 Correct 87 ms 188280 KB Output is correct
8 Correct 84 ms 188192 KB Output is correct
9 Correct 95 ms 188196 KB Output is correct
10 Correct 100 ms 188128 KB Output is correct
11 Correct 84 ms 188104 KB Output is correct
12 Correct 85 ms 188256 KB Output is correct
13 Correct 91 ms 188200 KB Output is correct
14 Correct 90 ms 188360 KB Output is correct
15 Correct 85 ms 188204 KB Output is correct
16 Correct 86 ms 188240 KB Output is correct
17 Correct 98 ms 188236 KB Output is correct
18 Correct 94 ms 188184 KB Output is correct
19 Correct 89 ms 188196 KB Output is correct
20 Correct 86 ms 188108 KB Output is correct
21 Correct 85 ms 188204 KB Output is correct
22 Correct 88 ms 188336 KB Output is correct
23 Correct 89 ms 188116 KB Output is correct
24 Correct 91 ms 188172 KB Output is correct
25 Correct 88 ms 188120 KB Output is correct
26 Correct 104 ms 190456 KB Output is correct
27 Correct 99 ms 189608 KB Output is correct
28 Correct 96 ms 189356 KB Output is correct
29 Correct 102 ms 189092 KB Output is correct
30 Correct 93 ms 188724 KB Output is correct
31 Correct 92 ms 188572 KB Output is correct
32 Correct 91 ms 188268 KB Output is correct
33 Correct 88 ms 188568 KB Output is correct
34 Correct 103 ms 189200 KB Output is correct
35 Correct 83 ms 188244 KB Output is correct
36 Correct 90 ms 188196 KB Output is correct
37 Correct 91 ms 188372 KB Output is correct
38 Correct 92 ms 188364 KB Output is correct
39 Correct 103 ms 188280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 188116 KB Output is correct
2 Correct 90 ms 188160 KB Output is correct
3 Correct 92 ms 188248 KB Output is correct
4 Correct 101 ms 188132 KB Output is correct
5 Correct 87 ms 188296 KB Output is correct
6 Correct 83 ms 188108 KB Output is correct
7 Correct 86 ms 188288 KB Output is correct
8 Correct 86 ms 188408 KB Output is correct
9 Correct 99 ms 188108 KB Output is correct
10 Correct 98 ms 188176 KB Output is correct
11 Correct 159 ms 192392 KB Output is correct
12 Correct 133 ms 191848 KB Output is correct
13 Correct 155 ms 192044 KB Output is correct
14 Correct 156 ms 192580 KB Output is correct
15 Correct 145 ms 192300 KB Output is correct
16 Correct 137 ms 192452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 188116 KB Output is correct
2 Correct 90 ms 188160 KB Output is correct
3 Correct 92 ms 188248 KB Output is correct
4 Correct 101 ms 188132 KB Output is correct
5 Correct 87 ms 188296 KB Output is correct
6 Correct 83 ms 188108 KB Output is correct
7 Correct 86 ms 188288 KB Output is correct
8 Correct 86 ms 188408 KB Output is correct
9 Correct 99 ms 188108 KB Output is correct
10 Correct 98 ms 188176 KB Output is correct
11 Correct 159 ms 192392 KB Output is correct
12 Correct 133 ms 191848 KB Output is correct
13 Correct 155 ms 192044 KB Output is correct
14 Correct 156 ms 192580 KB Output is correct
15 Correct 145 ms 192300 KB Output is correct
16 Correct 137 ms 192452 KB Output is correct
17 Correct 85 ms 188092 KB Output is correct
18 Correct 87 ms 188316 KB Output is correct
19 Correct 86 ms 188184 KB Output is correct
20 Correct 95 ms 188156 KB Output is correct
21 Correct 90 ms 188364 KB Output is correct
22 Correct 202 ms 192576 KB Output is correct
23 Correct 228 ms 192552 KB Output is correct
24 Correct 161 ms 191932 KB Output is correct
25 Correct 193 ms 192892 KB Output is correct
26 Correct 175 ms 192720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 188116 KB Output is correct
2 Correct 90 ms 188160 KB Output is correct
3 Correct 92 ms 188248 KB Output is correct
4 Correct 101 ms 188132 KB Output is correct
5 Correct 87 ms 188296 KB Output is correct
6 Correct 83 ms 188108 KB Output is correct
7 Correct 86 ms 188288 KB Output is correct
8 Correct 86 ms 188408 KB Output is correct
9 Correct 99 ms 188108 KB Output is correct
10 Correct 98 ms 188176 KB Output is correct
11 Correct 159 ms 192392 KB Output is correct
12 Correct 133 ms 191848 KB Output is correct
13 Correct 155 ms 192044 KB Output is correct
14 Correct 156 ms 192580 KB Output is correct
15 Correct 145 ms 192300 KB Output is correct
16 Correct 137 ms 192452 KB Output is correct
17 Correct 85 ms 188092 KB Output is correct
18 Correct 87 ms 188316 KB Output is correct
19 Correct 86 ms 188184 KB Output is correct
20 Correct 95 ms 188156 KB Output is correct
21 Correct 90 ms 188364 KB Output is correct
22 Correct 202 ms 192576 KB Output is correct
23 Correct 228 ms 192552 KB Output is correct
24 Correct 161 ms 191932 KB Output is correct
25 Correct 193 ms 192892 KB Output is correct
26 Correct 175 ms 192720 KB Output is correct
27 Correct 87 ms 188248 KB Output is correct
28 Correct 85 ms 188236 KB Output is correct
29 Correct 87 ms 188176 KB Output is correct
30 Correct 94 ms 188336 KB Output is correct
31 Correct 100 ms 188276 KB Output is correct
32 Correct 97 ms 188168 KB Output is correct
33 Correct 89 ms 188248 KB Output is correct
34 Correct 321 ms 192996 KB Output is correct
35 Correct 279 ms 192488 KB Output is correct
36 Correct 299 ms 192928 KB Output is correct
37 Correct 256 ms 193408 KB Output is correct
38 Correct 246 ms 192892 KB Output is correct
39 Correct 173 ms 191928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 188116 KB Output is correct
2 Correct 90 ms 188160 KB Output is correct
3 Correct 92 ms 188248 KB Output is correct
4 Correct 101 ms 188132 KB Output is correct
5 Correct 87 ms 188296 KB Output is correct
6 Correct 83 ms 188108 KB Output is correct
7 Correct 86 ms 188288 KB Output is correct
8 Correct 86 ms 188408 KB Output is correct
9 Correct 99 ms 188108 KB Output is correct
10 Correct 98 ms 188176 KB Output is correct
11 Correct 159 ms 192392 KB Output is correct
12 Correct 133 ms 191848 KB Output is correct
13 Correct 155 ms 192044 KB Output is correct
14 Correct 156 ms 192580 KB Output is correct
15 Correct 145 ms 192300 KB Output is correct
16 Correct 137 ms 192452 KB Output is correct
17 Correct 85 ms 188092 KB Output is correct
18 Correct 87 ms 188316 KB Output is correct
19 Correct 86 ms 188184 KB Output is correct
20 Correct 95 ms 188156 KB Output is correct
21 Correct 90 ms 188364 KB Output is correct
22 Correct 202 ms 192576 KB Output is correct
23 Correct 228 ms 192552 KB Output is correct
24 Correct 161 ms 191932 KB Output is correct
25 Correct 193 ms 192892 KB Output is correct
26 Correct 175 ms 192720 KB Output is correct
27 Correct 87 ms 188248 KB Output is correct
28 Correct 85 ms 188236 KB Output is correct
29 Correct 87 ms 188176 KB Output is correct
30 Correct 94 ms 188336 KB Output is correct
31 Correct 100 ms 188276 KB Output is correct
32 Correct 97 ms 188168 KB Output is correct
33 Correct 89 ms 188248 KB Output is correct
34 Correct 321 ms 192996 KB Output is correct
35 Correct 279 ms 192488 KB Output is correct
36 Correct 299 ms 192928 KB Output is correct
37 Correct 256 ms 193408 KB Output is correct
38 Correct 246 ms 192892 KB Output is correct
39 Correct 173 ms 191928 KB Output is correct
40 Correct 89 ms 188720 KB Output is correct
41 Correct 95 ms 188544 KB Output is correct
42 Correct 100 ms 188360 KB Output is correct
43 Correct 95 ms 188396 KB Output is correct
44 Correct 417 ms 194896 KB Output is correct
45 Correct 411 ms 194552 KB Output is correct
46 Correct 446 ms 194340 KB Output is correct
47 Correct 373 ms 194672 KB Output is correct
48 Correct 250 ms 193940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 188164 KB Output is correct
2 Correct 86 ms 188164 KB Output is correct
3 Correct 84 ms 188080 KB Output is correct
4 Correct 92 ms 188188 KB Output is correct
5 Correct 89 ms 188104 KB Output is correct
6 Correct 84 ms 188148 KB Output is correct
7 Correct 87 ms 188280 KB Output is correct
8 Correct 84 ms 188192 KB Output is correct
9 Correct 95 ms 188196 KB Output is correct
10 Correct 100 ms 188128 KB Output is correct
11 Correct 84 ms 188104 KB Output is correct
12 Correct 85 ms 188256 KB Output is correct
13 Correct 91 ms 188200 KB Output is correct
14 Correct 90 ms 188360 KB Output is correct
15 Correct 85 ms 188204 KB Output is correct
16 Correct 86 ms 188240 KB Output is correct
17 Correct 98 ms 188236 KB Output is correct
18 Correct 94 ms 188184 KB Output is correct
19 Correct 89 ms 188196 KB Output is correct
20 Correct 86 ms 188108 KB Output is correct
21 Correct 85 ms 188204 KB Output is correct
22 Correct 88 ms 188336 KB Output is correct
23 Correct 89 ms 188116 KB Output is correct
24 Correct 91 ms 188172 KB Output is correct
25 Correct 88 ms 188120 KB Output is correct
26 Correct 104 ms 190456 KB Output is correct
27 Correct 99 ms 189608 KB Output is correct
28 Correct 96 ms 189356 KB Output is correct
29 Correct 102 ms 189092 KB Output is correct
30 Correct 93 ms 188724 KB Output is correct
31 Correct 92 ms 188572 KB Output is correct
32 Correct 91 ms 188268 KB Output is correct
33 Correct 88 ms 188568 KB Output is correct
34 Correct 103 ms 189200 KB Output is correct
35 Correct 83 ms 188244 KB Output is correct
36 Correct 90 ms 188196 KB Output is correct
37 Correct 91 ms 188372 KB Output is correct
38 Correct 92 ms 188364 KB Output is correct
39 Correct 103 ms 188280 KB Output is correct
40 Correct 83 ms 188116 KB Output is correct
41 Correct 90 ms 188160 KB Output is correct
42 Correct 92 ms 188248 KB Output is correct
43 Correct 101 ms 188132 KB Output is correct
44 Correct 87 ms 188296 KB Output is correct
45 Correct 83 ms 188108 KB Output is correct
46 Correct 86 ms 188288 KB Output is correct
47 Correct 86 ms 188408 KB Output is correct
48 Correct 99 ms 188108 KB Output is correct
49 Correct 98 ms 188176 KB Output is correct
50 Correct 159 ms 192392 KB Output is correct
51 Correct 133 ms 191848 KB Output is correct
52 Correct 155 ms 192044 KB Output is correct
53 Correct 156 ms 192580 KB Output is correct
54 Correct 145 ms 192300 KB Output is correct
55 Correct 137 ms 192452 KB Output is correct
56 Correct 85 ms 188092 KB Output is correct
57 Correct 87 ms 188316 KB Output is correct
58 Correct 86 ms 188184 KB Output is correct
59 Correct 95 ms 188156 KB Output is correct
60 Correct 90 ms 188364 KB Output is correct
61 Correct 202 ms 192576 KB Output is correct
62 Correct 228 ms 192552 KB Output is correct
63 Correct 161 ms 191932 KB Output is correct
64 Correct 193 ms 192892 KB Output is correct
65 Correct 175 ms 192720 KB Output is correct
66 Correct 87 ms 188248 KB Output is correct
67 Correct 85 ms 188236 KB Output is correct
68 Correct 87 ms 188176 KB Output is correct
69 Correct 94 ms 188336 KB Output is correct
70 Correct 100 ms 188276 KB Output is correct
71 Correct 97 ms 188168 KB Output is correct
72 Correct 89 ms 188248 KB Output is correct
73 Correct 321 ms 192996 KB Output is correct
74 Correct 279 ms 192488 KB Output is correct
75 Correct 299 ms 192928 KB Output is correct
76 Correct 256 ms 193408 KB Output is correct
77 Correct 246 ms 192892 KB Output is correct
78 Correct 173 ms 191928 KB Output is correct
79 Correct 89 ms 188720 KB Output is correct
80 Correct 95 ms 188544 KB Output is correct
81 Correct 100 ms 188360 KB Output is correct
82 Correct 95 ms 188396 KB Output is correct
83 Correct 417 ms 194896 KB Output is correct
84 Correct 411 ms 194552 KB Output is correct
85 Correct 446 ms 194340 KB Output is correct
86 Correct 373 ms 194672 KB Output is correct
87 Correct 250 ms 193940 KB Output is correct
88 Correct 1638 ms 271120 KB Output is correct
89 Correct 1036 ms 229876 KB Output is correct
90 Correct 1327 ms 245628 KB Output is correct
91 Correct 775 ms 220392 KB Output is correct
92 Correct 672 ms 200636 KB Output is correct
93 Correct 854 ms 221220 KB Output is correct
94 Correct 627 ms 206404 KB Output is correct
95 Correct 377 ms 203152 KB Output is correct
96 Correct 691 ms 226356 KB Output is correct
97 Correct 182 ms 194328 KB Output is correct
98 Correct 307 ms 197788 KB Output is correct
99 Correct 379 ms 197804 KB Output is correct