Submission #711311

# Submission time Handle Problem Language Result Execution time Memory
711311 2023-03-16T14:46:33 Z kostia244 Team Contest (JOI22_team) C++17
100 / 100
185 ms 15384 KB
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int inf = 1<<28;

struct Fenwick {
    vector<int> f;
    Fenwick(int n) : f(n, -inf) {}
    void upd(int pos, int val) {
        for(; pos < f.size(); pos += pos & -pos)
            f[pos] = max(f[pos], val);
    }
    int get(int pos) {
        int res = -inf;
        for(; pos; pos -= pos & -pos)
            res = max(res, f[pos]);
        return res;
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<array<int, 3>> a(n);
    vector<int> Y, yid(n), B(n, inf);
    Fenwick A(n + 1);
    for(auto &[x, y, z] : a) {
        cin >> x >> y >> z;
        Y.push_back(y);
    }
    sort(all(a));
    a.erase(unique(all(a)), a.end());
    sort(all(Y));
    Y.erase(unique(all(Y)), Y.end());
    for(int i = 0; i < n; i++)
        yid[i] = lower_bound(all(Y), a[i][1]) - Y.begin();
    n = a.size();

    set<int> legal_b, blocked_b;
    auto add = [&](int i) {
        int y_id = yid[i];
        int z = a[i][2];
        if(legal_b.count(y_id)) {
            legal_b.erase(y_id);
        }
        if(blocked_b.count(y_id)) {
            blocked_b.erase(y_id);
        }

        B[y_id] = min(B[y_id], z);
        A.upd(y_id + 1, z);

        int zmax = A.get(y_id);
        if(zmax > B[y_id])
            legal_b.insert(y_id);
        else
            blocked_b.insert(y_id);
        
        auto it = blocked_b.upper_bound(y_id);
        while(it != blocked_b.end()) {
            int pos = *it;
            if(B[pos] < z) {
                blocked_b.erase(pos);
                legal_b.insert(pos);
            } else 
                break;
            it = blocked_b.upper_bound(y_id);
        }
    };
    auto query = [&](int ly, int z) {
        if(legal_b.empty()) return -inf;
        int pos = *legal_b.rbegin();
        int zmax = A.get(pos);
        // cout << "cut at " << pos << " \\ " << zmax << endl;
        if(pos <= ly || zmax <= z) return -inf;
        return Y[pos] + zmax;
    };

    int ans = -1;
    for(int j = 0, i = 0; i < n; i++) {//z
        while(a[j][0] < a[i][0]) {
            add(j++);
        }
        // cout << "Ask " << a[i][0] << " " << a[i][1] << " " << a[i][2] << " " << yid[i] << endl;
        ans = max(ans, a[i][0] + query(yid[i], a[i][2]));
    }
    cout << ans << '\n';
}

Compilation message

team.cpp: In member function 'void Fenwick::upd(int, int)':
team.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         for(; pos < f.size(); pos += pos & -pos)
      |               ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 5 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 452 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 51 ms 5008 KB Output is correct
12 Correct 27 ms 3288 KB Output is correct
13 Correct 30 ms 3800 KB Output is correct
14 Correct 46 ms 5008 KB Output is correct
15 Correct 40 ms 4928 KB Output is correct
16 Correct 37 ms 5000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 51 ms 5008 KB Output is correct
12 Correct 27 ms 3288 KB Output is correct
13 Correct 30 ms 3800 KB Output is correct
14 Correct 46 ms 5008 KB Output is correct
15 Correct 40 ms 4928 KB Output is correct
16 Correct 37 ms 5000 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 58 ms 5096 KB Output is correct
23 Correct 46 ms 4856 KB Output is correct
24 Correct 34 ms 3536 KB Output is correct
25 Correct 48 ms 4944 KB Output is correct
26 Correct 42 ms 4932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 51 ms 5008 KB Output is correct
12 Correct 27 ms 3288 KB Output is correct
13 Correct 30 ms 3800 KB Output is correct
14 Correct 46 ms 5008 KB Output is correct
15 Correct 40 ms 4928 KB Output is correct
16 Correct 37 ms 5000 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 58 ms 5096 KB Output is correct
23 Correct 46 ms 4856 KB Output is correct
24 Correct 34 ms 3536 KB Output is correct
25 Correct 48 ms 4944 KB Output is correct
26 Correct 42 ms 4932 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 87 ms 4788 KB Output is correct
35 Correct 79 ms 4680 KB Output is correct
36 Correct 82 ms 4940 KB Output is correct
37 Correct 76 ms 4940 KB Output is correct
38 Correct 46 ms 4840 KB Output is correct
39 Correct 25 ms 3088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 51 ms 5008 KB Output is correct
12 Correct 27 ms 3288 KB Output is correct
13 Correct 30 ms 3800 KB Output is correct
14 Correct 46 ms 5008 KB Output is correct
15 Correct 40 ms 4928 KB Output is correct
16 Correct 37 ms 5000 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 58 ms 5096 KB Output is correct
23 Correct 46 ms 4856 KB Output is correct
24 Correct 34 ms 3536 KB Output is correct
25 Correct 48 ms 4944 KB Output is correct
26 Correct 42 ms 4932 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 87 ms 4788 KB Output is correct
35 Correct 79 ms 4680 KB Output is correct
36 Correct 82 ms 4940 KB Output is correct
37 Correct 76 ms 4940 KB Output is correct
38 Correct 46 ms 4840 KB Output is correct
39 Correct 25 ms 3088 KB Output is correct
40 Correct 3 ms 468 KB Output is correct
41 Correct 4 ms 464 KB Output is correct
42 Correct 3 ms 492 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 114 ms 4984 KB Output is correct
45 Correct 111 ms 4948 KB Output is correct
46 Correct 113 ms 4992 KB Output is correct
47 Correct 111 ms 5020 KB Output is correct
48 Correct 53 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 5 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 452 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 51 ms 5008 KB Output is correct
51 Correct 27 ms 3288 KB Output is correct
52 Correct 30 ms 3800 KB Output is correct
53 Correct 46 ms 5008 KB Output is correct
54 Correct 40 ms 4928 KB Output is correct
55 Correct 37 ms 5000 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 58 ms 5096 KB Output is correct
62 Correct 46 ms 4856 KB Output is correct
63 Correct 34 ms 3536 KB Output is correct
64 Correct 48 ms 4944 KB Output is correct
65 Correct 42 ms 4932 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 3 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 87 ms 4788 KB Output is correct
74 Correct 79 ms 4680 KB Output is correct
75 Correct 82 ms 4940 KB Output is correct
76 Correct 76 ms 4940 KB Output is correct
77 Correct 46 ms 4840 KB Output is correct
78 Correct 25 ms 3088 KB Output is correct
79 Correct 3 ms 468 KB Output is correct
80 Correct 4 ms 464 KB Output is correct
81 Correct 3 ms 492 KB Output is correct
82 Correct 3 ms 468 KB Output is correct
83 Correct 114 ms 4984 KB Output is correct
84 Correct 111 ms 4948 KB Output is correct
85 Correct 113 ms 4992 KB Output is correct
86 Correct 111 ms 5020 KB Output is correct
87 Correct 53 ms 4972 KB Output is correct
88 Correct 161 ms 11468 KB Output is correct
89 Correct 177 ms 12168 KB Output is correct
90 Correct 185 ms 12700 KB Output is correct
91 Correct 154 ms 11392 KB Output is correct
92 Correct 140 ms 8152 KB Output is correct
93 Correct 172 ms 11308 KB Output is correct
94 Correct 155 ms 9496 KB Output is correct
95 Correct 71 ms 8376 KB Output is correct
96 Correct 157 ms 15384 KB Output is correct
97 Correct 60 ms 8692 KB Output is correct
98 Correct 112 ms 9336 KB Output is correct
99 Correct 134 ms 9284 KB Output is correct