# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884701 |
2023-12-08T06:33:29 Z |
Desh03 |
Team Contest (JOI22_team) |
C++17 |
|
2000 ms |
246516 KB |
#include <bits/stdc++.h>
using namespace std;
void chmax(int &x, const int &y) {
x = (x > y ? x : y);
}
struct Fenwick {
vector<int> f;
int n;
Fenwick(int n_) : n(n_) {
f.resize(n);
}
void upd(int i, int x) {
while (i < n) {
chmax(f[i], x);
i |= i + 1;
}
}
int qry(int i) {
int x = 0;
while (i >= 0) {
chmax(x, f[i]);
i = (i & i + 1) - 1;
}
return x;
}
};
struct Fenwick2D {
vector<unordered_map<int, int>> f;
int nx, ny;
Fenwick2D(int nx_, int ny_) : nx(nx_), ny(ny_) {
f.resize(nx_);
}
void upd(int i, int J, int x) {
while (i >= 0) {
for (int j = J; j >= 0; j = (j & j + 1) - 1) {
chmax(f[i][j], x);
}
i = (i & i + 1) - 1;
}
}
int qry(int i, int J) {
int x = 0;
while (i < nx) {
for (int j = J; j < ny; j |= j + 1) {
chmax(x, f[i][j]);
}
i |= i + 1;
}
return x;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<tuple<int, int, int>> a(n);
vector<int> cmpx, cmpy, cmpz;
for (auto &[x, y, z] : a) {
cin >> x >> y >> z;
cmpx.push_back(x);
cmpy.push_back(y);
cmpz.push_back(z);
}
sort(cmpx.begin(), cmpx.end());
cmpx.erase(unique(cmpx.begin(), cmpx.end()), cmpx.end());
sort(cmpy.begin(), cmpy.end());
cmpy.erase(unique(cmpy.begin(), cmpy.end()), cmpy.end());
sort(cmpz.begin(), cmpz.end());
cmpz.erase(unique(cmpz.begin(), cmpz.end()), cmpz.end());
vector<vector<pair<int, int>>> X(cmpx.size());
for (auto &[x, y, z] : a) {
X[lower_bound(cmpx.begin(), cmpx.end(), x) - cmpx.begin()].push_back({lower_bound(cmpy.begin(), cmpy.end(), y) - cmpy.begin(), lower_bound(cmpz.begin(), cmpz.end(), z) - cmpz.begin()});
}
Fenwick fy(cmpy.size()), fz(cmpz.size());
Fenwick2D fyz(cmpy.size(), cmpz.size());
int ans = -1;
for (int x = 0; x < cmpx.size(); x++) {
for (auto &[y, z] : X[x]) {
int wyz = fyz.qry(y + 1, z + 1);
if (wyz) chmax(ans, cmpx[x] + wyz);
}
for (auto &[y, z] : X[x]) {
int wz = fy.qry(y - 1), wy = fz.qry(z - 1);
if (wz > z) fyz.upd(y, wz, cmpy[y] + cmpz[wz]);
if (wy > y) fyz.upd(wy, z, cmpy[wy] + cmpz[z]);
fy.upd(y, z);
fz.upd(z, y);
}
}
cout << ans << '\n';
return 0;
}
Compilation message
team.cpp: In member function 'int Fenwick::qry(int)':
team.cpp:25:24: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
25 | i = (i & i + 1) - 1;
| ~~^~~
team.cpp: In member function 'void Fenwick2D::upd(int, int, int)':
team.cpp:39:48: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
39 | for (int j = J; j >= 0; j = (j & j + 1) - 1) {
| ~~^~~
team.cpp:42:24: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
42 | i = (i & i + 1) - 1;
| ~~^~~
team.cpp: In function 'int main()':
team.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int x = 0; x < cmpx.size(); x++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
33 ms |
7544 KB |
Output is correct |
27 |
Correct |
19 ms |
5208 KB |
Output is correct |
28 |
Correct |
15 ms |
4444 KB |
Output is correct |
29 |
Correct |
11 ms |
3160 KB |
Output is correct |
30 |
Correct |
9 ms |
2904 KB |
Output is correct |
31 |
Correct |
13 ms |
3164 KB |
Output is correct |
32 |
Correct |
6 ms |
1112 KB |
Output is correct |
33 |
Correct |
2 ms |
848 KB |
Output is correct |
34 |
Correct |
9 ms |
2908 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
1396 KB |
Output is correct |
38 |
Correct |
5 ms |
1372 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
46 ms |
5636 KB |
Output is correct |
12 |
Correct |
27 ms |
4048 KB |
Output is correct |
13 |
Correct |
28 ms |
5556 KB |
Output is correct |
14 |
Correct |
42 ms |
7100 KB |
Output is correct |
15 |
Correct |
35 ms |
6596 KB |
Output is correct |
16 |
Correct |
28 ms |
6972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
46 ms |
5636 KB |
Output is correct |
12 |
Correct |
27 ms |
4048 KB |
Output is correct |
13 |
Correct |
28 ms |
5556 KB |
Output is correct |
14 |
Correct |
42 ms |
7100 KB |
Output is correct |
15 |
Correct |
35 ms |
6596 KB |
Output is correct |
16 |
Correct |
28 ms |
6972 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
64 ms |
6328 KB |
Output is correct |
23 |
Correct |
57 ms |
6200 KB |
Output is correct |
24 |
Correct |
43 ms |
4804 KB |
Output is correct |
25 |
Correct |
70 ms |
6776 KB |
Output is correct |
26 |
Correct |
37 ms |
6724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
46 ms |
5636 KB |
Output is correct |
12 |
Correct |
27 ms |
4048 KB |
Output is correct |
13 |
Correct |
28 ms |
5556 KB |
Output is correct |
14 |
Correct |
42 ms |
7100 KB |
Output is correct |
15 |
Correct |
35 ms |
6596 KB |
Output is correct |
16 |
Correct |
28 ms |
6972 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
64 ms |
6328 KB |
Output is correct |
23 |
Correct |
57 ms |
6200 KB |
Output is correct |
24 |
Correct |
43 ms |
4804 KB |
Output is correct |
25 |
Correct |
70 ms |
6776 KB |
Output is correct |
26 |
Correct |
37 ms |
6724 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
158 ms |
10540 KB |
Output is correct |
35 |
Correct |
130 ms |
10132 KB |
Output is correct |
36 |
Correct |
131 ms |
10312 KB |
Output is correct |
37 |
Correct |
107 ms |
9784 KB |
Output is correct |
38 |
Correct |
54 ms |
7100 KB |
Output is correct |
39 |
Correct |
50 ms |
8188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
46 ms |
5636 KB |
Output is correct |
12 |
Correct |
27 ms |
4048 KB |
Output is correct |
13 |
Correct |
28 ms |
5556 KB |
Output is correct |
14 |
Correct |
42 ms |
7100 KB |
Output is correct |
15 |
Correct |
35 ms |
6596 KB |
Output is correct |
16 |
Correct |
28 ms |
6972 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
64 ms |
6328 KB |
Output is correct |
23 |
Correct |
57 ms |
6200 KB |
Output is correct |
24 |
Correct |
43 ms |
4804 KB |
Output is correct |
25 |
Correct |
70 ms |
6776 KB |
Output is correct |
26 |
Correct |
37 ms |
6724 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
158 ms |
10540 KB |
Output is correct |
35 |
Correct |
130 ms |
10132 KB |
Output is correct |
36 |
Correct |
131 ms |
10312 KB |
Output is correct |
37 |
Correct |
107 ms |
9784 KB |
Output is correct |
38 |
Correct |
54 ms |
7100 KB |
Output is correct |
39 |
Correct |
50 ms |
8188 KB |
Output is correct |
40 |
Correct |
9 ms |
2908 KB |
Output is correct |
41 |
Correct |
13 ms |
3292 KB |
Output is correct |
42 |
Correct |
4 ms |
1372 KB |
Output is correct |
43 |
Correct |
5 ms |
1372 KB |
Output is correct |
44 |
Correct |
1035 ms |
70832 KB |
Output is correct |
45 |
Correct |
493 ms |
61288 KB |
Output is correct |
46 |
Correct |
523 ms |
65208 KB |
Output is correct |
47 |
Correct |
450 ms |
60528 KB |
Output is correct |
48 |
Correct |
72 ms |
7788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
33 ms |
7544 KB |
Output is correct |
27 |
Correct |
19 ms |
5208 KB |
Output is correct |
28 |
Correct |
15 ms |
4444 KB |
Output is correct |
29 |
Correct |
11 ms |
3160 KB |
Output is correct |
30 |
Correct |
9 ms |
2904 KB |
Output is correct |
31 |
Correct |
13 ms |
3164 KB |
Output is correct |
32 |
Correct |
6 ms |
1112 KB |
Output is correct |
33 |
Correct |
2 ms |
848 KB |
Output is correct |
34 |
Correct |
9 ms |
2908 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
1396 KB |
Output is correct |
38 |
Correct |
5 ms |
1372 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
46 ms |
5636 KB |
Output is correct |
51 |
Correct |
27 ms |
4048 KB |
Output is correct |
52 |
Correct |
28 ms |
5556 KB |
Output is correct |
53 |
Correct |
42 ms |
7100 KB |
Output is correct |
54 |
Correct |
35 ms |
6596 KB |
Output is correct |
55 |
Correct |
28 ms |
6972 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
64 ms |
6328 KB |
Output is correct |
62 |
Correct |
57 ms |
6200 KB |
Output is correct |
63 |
Correct |
43 ms |
4804 KB |
Output is correct |
64 |
Correct |
70 ms |
6776 KB |
Output is correct |
65 |
Correct |
37 ms |
6724 KB |
Output is correct |
66 |
Correct |
1 ms |
856 KB |
Output is correct |
67 |
Correct |
1 ms |
348 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
4 ms |
1372 KB |
Output is correct |
71 |
Correct |
1 ms |
604 KB |
Output is correct |
72 |
Correct |
1 ms |
604 KB |
Output is correct |
73 |
Correct |
158 ms |
10540 KB |
Output is correct |
74 |
Correct |
130 ms |
10132 KB |
Output is correct |
75 |
Correct |
131 ms |
10312 KB |
Output is correct |
76 |
Correct |
107 ms |
9784 KB |
Output is correct |
77 |
Correct |
54 ms |
7100 KB |
Output is correct |
78 |
Correct |
50 ms |
8188 KB |
Output is correct |
79 |
Correct |
9 ms |
2908 KB |
Output is correct |
80 |
Correct |
13 ms |
3292 KB |
Output is correct |
81 |
Correct |
4 ms |
1372 KB |
Output is correct |
82 |
Correct |
5 ms |
1372 KB |
Output is correct |
83 |
Correct |
1035 ms |
70832 KB |
Output is correct |
84 |
Correct |
493 ms |
61288 KB |
Output is correct |
85 |
Correct |
523 ms |
65208 KB |
Output is correct |
86 |
Correct |
450 ms |
60528 KB |
Output is correct |
87 |
Correct |
72 ms |
7788 KB |
Output is correct |
88 |
Execution timed out |
2045 ms |
246516 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |