Submission #938613

# Submission time Handle Problem Language Result Execution time Memory
938613 2024-03-05T11:14:08 Z Pannda Team Contest (JOI22_team) C++17
100 / 100
276 ms 33104 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("inp.inp", "r", stdin);
//    freopen("out.out", "w", stdout);

    int n;
    cin >> n;
    map<int, vector<array<int, 2>>> mp;
    for (int i = 0; i < n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        mp[z].push_back({x, y});
    }

    set<array<int, 2>> xy;
    set<array<int, 2>> yx;
    set<array<int, 2>> xy_defer;
    set<array<int, 2>> yx_defer;
    static const int INF = 1e9;

    auto add = [&](int x, int y) -> void {
        while (!xy_defer.empty()) {
            auto it = xy_defer.lower_bound(array<int, 2>{x, -INF});
            if (it == xy_defer.begin()) break;
            it--;
            auto [xx, yy] = *it;
            if (yy <= y) break;
            xy_defer.erase(it);
            yx_defer.erase({yy, xx});
            xy.insert({xx, yy});
            yx.insert({yy, xx});
        }
        while (!yx_defer.empty()) {
            auto it = yx_defer.lower_bound(array<int, 2>{y, -INF});
            if (it == yx_defer.begin()) break;
            it--;
            auto [yy, xx] = *it;
            if (xx <= x) break;
            yx_defer.erase(it);
            xy_defer.erase({xx, yy});
            xy.insert({xx, yy});
            yx.insert({yy, xx});
        }
        bool should_insert;
        if (xy.empty()) {
            should_insert = false;
        } else {
            int xx = (*xy.rbegin())[0];
            int yy = (*yx.rbegin())[0];
            if (xx > x || yy > y) {
                should_insert = true;
            } else {
                should_insert = false;
            }
        }
        if (should_insert) {
            xy.insert({x, y});
            yx.insert({y, x});
        } else {
            xy_defer.insert({x, y});
            yx_defer.insert({y, x});
        }
    };

    auto query = [&](int x, int y) -> int {
        if (xy.empty()) return -INF;
        int xx = (*xy.rbegin())[0];
        int yy = (*yx.rbegin())[0];
        if (xx <= x || yy <= y) return -INF;
        return xx + yy;
    };

    int res = -1;
    for (auto [z, xy] : mp) {
        for (auto [x, y] : xy) {
            res = max(res, z + query(x, y));
        }
        for (auto [x, y] : xy) {
            add(x, y);
        }
    }
    cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 1 ms 348 KB Output is correct
9 Correct 0 ms 360 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 1 ms 348 KB Output is correct
9 Correct 0 ms 360 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 4 ms 1112 KB Output is correct
27 Correct 4 ms 1112 KB Output is correct
28 Correct 5 ms 1628 KB Output is correct
29 Correct 4 ms 1112 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 2 ms 780 KB Output is correct
34 Correct 4 ms 1372 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 3 ms 860 KB Output is correct
38 Correct 2 ms 796 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 30 ms 1892 KB Output is correct
12 Correct 20 ms 1744 KB Output is correct
13 Correct 25 ms 2288 KB Output is correct
14 Correct 31 ms 2512 KB Output is correct
15 Correct 30 ms 2604 KB Output is correct
16 Correct 25 ms 2980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 30 ms 1892 KB Output is correct
12 Correct 20 ms 1744 KB Output is correct
13 Correct 25 ms 2288 KB Output is correct
14 Correct 31 ms 2512 KB Output is correct
15 Correct 30 ms 2604 KB Output is correct
16 Correct 25 ms 2980 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 44 ms 1864 KB Output is correct
23 Correct 34 ms 1876 KB Output is correct
24 Correct 29 ms 1800 KB Output is correct
25 Correct 42 ms 3136 KB Output is correct
26 Correct 27 ms 3392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 30 ms 1892 KB Output is correct
12 Correct 20 ms 1744 KB Output is correct
13 Correct 25 ms 2288 KB Output is correct
14 Correct 31 ms 2512 KB Output is correct
15 Correct 30 ms 2604 KB Output is correct
16 Correct 25 ms 2980 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 44 ms 1864 KB Output is correct
23 Correct 34 ms 1876 KB Output is correct
24 Correct 29 ms 1800 KB Output is correct
25 Correct 42 ms 3136 KB Output is correct
26 Correct 27 ms 3392 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 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 3 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 117 ms 9552 KB Output is correct
35 Correct 86 ms 8272 KB Output is correct
36 Correct 106 ms 7504 KB Output is correct
37 Correct 77 ms 6992 KB Output is correct
38 Correct 36 ms 3612 KB Output is correct
39 Correct 32 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 30 ms 1892 KB Output is correct
12 Correct 20 ms 1744 KB Output is correct
13 Correct 25 ms 2288 KB Output is correct
14 Correct 31 ms 2512 KB Output is correct
15 Correct 30 ms 2604 KB Output is correct
16 Correct 25 ms 2980 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 44 ms 1864 KB Output is correct
23 Correct 34 ms 1876 KB Output is correct
24 Correct 29 ms 1800 KB Output is correct
25 Correct 42 ms 3136 KB Output is correct
26 Correct 27 ms 3392 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 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 3 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 117 ms 9552 KB Output is correct
35 Correct 86 ms 8272 KB Output is correct
36 Correct 106 ms 7504 KB Output is correct
37 Correct 77 ms 6992 KB Output is correct
38 Correct 36 ms 3612 KB Output is correct
39 Correct 32 ms 2648 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 4 ms 860 KB Output is correct
42 Correct 2 ms 824 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 174 ms 18004 KB Output is correct
45 Correct 129 ms 13680 KB Output is correct
46 Correct 139 ms 15188 KB Output is correct
47 Correct 124 ms 13392 KB Output is correct
48 Correct 49 ms 4404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 1 ms 348 KB Output is correct
9 Correct 0 ms 360 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 4 ms 1112 KB Output is correct
27 Correct 4 ms 1112 KB Output is correct
28 Correct 5 ms 1628 KB Output is correct
29 Correct 4 ms 1112 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 2 ms 780 KB Output is correct
34 Correct 4 ms 1372 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 3 ms 860 KB Output is correct
38 Correct 2 ms 796 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 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 30 ms 1892 KB Output is correct
51 Correct 20 ms 1744 KB Output is correct
52 Correct 25 ms 2288 KB Output is correct
53 Correct 31 ms 2512 KB Output is correct
54 Correct 30 ms 2604 KB Output is correct
55 Correct 25 ms 2980 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 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 44 ms 1864 KB Output is correct
62 Correct 34 ms 1876 KB Output is correct
63 Correct 29 ms 1800 KB Output is correct
64 Correct 42 ms 3136 KB Output is correct
65 Correct 27 ms 3392 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 0 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 3 ms 604 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 117 ms 9552 KB Output is correct
74 Correct 86 ms 8272 KB Output is correct
75 Correct 106 ms 7504 KB Output is correct
76 Correct 77 ms 6992 KB Output is correct
77 Correct 36 ms 3612 KB Output is correct
78 Correct 32 ms 2648 KB Output is correct
79 Correct 2 ms 860 KB Output is correct
80 Correct 4 ms 860 KB Output is correct
81 Correct 2 ms 824 KB Output is correct
82 Correct 3 ms 860 KB Output is correct
83 Correct 174 ms 18004 KB Output is correct
84 Correct 129 ms 13680 KB Output is correct
85 Correct 139 ms 15188 KB Output is correct
86 Correct 124 ms 13392 KB Output is correct
87 Correct 49 ms 4404 KB Output is correct
88 Correct 276 ms 33100 KB Output is correct
89 Correct 194 ms 25504 KB Output is correct
90 Correct 221 ms 26960 KB Output is correct
91 Correct 211 ms 23780 KB Output is correct
92 Correct 183 ms 20052 KB Output is correct
93 Correct 213 ms 25428 KB Output is correct
94 Correct 181 ms 21200 KB Output is correct
95 Correct 85 ms 15296 KB Output is correct
96 Correct 213 ms 33104 KB Output is correct
97 Correct 36 ms 5068 KB Output is correct
98 Correct 105 ms 17488 KB Output is correct
99 Correct 114 ms 17596 KB Output is correct