Submission #553755

# Submission time Handle Problem Language Result Execution time Memory
553755 2022-04-26T20:14:27 Z LucaDantas Team Contest (JOI22_team) C++17
36 / 100
96 ms 8660 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 1<<18; // tem q ser pot de 2 pra seg

struct Pt {
    int x, y, z;
    bool operator<(const Pt& o) { return z < o.z; }
} pt[maxn];

struct SegmentTree {
    int mx[maxn<<1], mn[maxn<<1];
    SegmentTree() { for(int i = 0; i < (maxn<<1); i++) mx[i] = -0x3f3f3f3f, mn[i] = 0x3f3f3f3f; }
    void upd(int x, int v) {
        // printf("upd %d %d\n", x, v);
        x += maxn;
        for(mx[x] = max(mx[x], v), mn[x] = min(mn[x], v); x > 1; x >>= 1)
            mx[x>>1] = max(mx[x], mx[x^1]), mn[x>>1] = min(mn[x], mn[x^1]);
    }
    int query(int l, int r) {
        // maximum in this segment
        // printf("query %d %d == ", l, r);
        r++;
        int ans = -0x3f3f3f3f;
        for(l += maxn, r += maxn; l < r; l >>= 1, r >>= 1) {
            if(l&1) ans = max(ans, mx[l++]);
            if(r&1) ans = max(ans, mx[--r]);
        }
        // printf("%d\n", ans);
        return ans;
    }
    int find(int v) {
        int x = 1;
        while(x < maxn)
            if(mn[x<<1|1] < v)
                x <<= 1, x |= 1;
            else
                x <<= 1;
        // printf("find - %d %d\n", v, x-maxn);
        return x - maxn;
    }
} seg;

struct ST {
    // vector<pair<int,int>> ans; // still brute
    pair<int,int> ans;
    void calc(int x, int y) {
        int maior = seg.query(0, x-1);
        if(maior > y)
            // ans.push_back({x, maior});
            ans = max(ans, {x, maior});
        int pos = seg.find(y);
        if(pos > x)
            ans = max(ans, {pos, y});
            // ans.push_back({pos, y});
    }
    void insert(int x, int y) { seg.upd(x, y); }
    int get(int x, int y) {
        int aq = -0x3f3f3f3f;
        // for(auto [x2, y2] : ans)
        auto [x2, y2] = ans;
            if(x2 > x && y2 > y) aq = max(aq, x2+y2);
        return aq;
    }
} st;

int main() {
    int n; scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        int x, y, z; scanf("%d %d %d", &x, &y, &z);
        pt[i] = {x, y, z};
    }
    sort(pt, pt+n);
    int ans = -1;
    for(int i = 0, j = 0; i < n; i = j) {
        for(; j < n && pt[i].z == pt[j].z; j++)
            ans = max(ans, st.get(pt[j].x, pt[j].y) + pt[j].z);
        for(j = i; j < n && pt[i].z == pt[j].z; j++)
            st.insert(pt[j].x, pt[j].y);
        for(j = i; j < n && pt[i].z == pt[j].z; j++)
            st.calc(pt[j].x, pt[j].y);
        // puts("");
    }
    printf("%d\n", ans);
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:68:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     int n; scanf("%d", &n);
      |            ~~~~~^~~~~~~~~~
team.cpp:70:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         int x, y, z; scanf("%d %d %d", &x, &y, &z);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4412 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 3 ms 4412 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Runtime error 6 ms 8660 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4412 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 3 ms 4412 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Runtime error 6 ms 8660 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4408 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4408 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 96 ms 6276 KB Output is correct
12 Correct 58 ms 5876 KB Output is correct
13 Correct 69 ms 6536 KB Output is correct
14 Correct 86 ms 6796 KB Output is correct
15 Correct 84 ms 6500 KB Output is correct
16 Correct 83 ms 6660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4408 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4408 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 96 ms 6276 KB Output is correct
12 Correct 58 ms 5876 KB Output is correct
13 Correct 69 ms 6536 KB Output is correct
14 Correct 86 ms 6796 KB Output is correct
15 Correct 84 ms 6500 KB Output is correct
16 Correct 83 ms 6660 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 2 ms 4408 KB Output is correct
19 Correct 3 ms 4436 KB Output is correct
20 Correct 3 ms 4404 KB Output is correct
21 Correct 4 ms 4424 KB Output is correct
22 Correct 87 ms 6936 KB Output is correct
23 Correct 93 ms 6944 KB Output is correct
24 Correct 65 ms 6188 KB Output is correct
25 Correct 85 ms 7192 KB Output is correct
26 Correct 88 ms 7084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4408 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4408 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 96 ms 6276 KB Output is correct
12 Correct 58 ms 5876 KB Output is correct
13 Correct 69 ms 6536 KB Output is correct
14 Correct 86 ms 6796 KB Output is correct
15 Correct 84 ms 6500 KB Output is correct
16 Correct 83 ms 6660 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 2 ms 4408 KB Output is correct
19 Correct 3 ms 4436 KB Output is correct
20 Correct 3 ms 4404 KB Output is correct
21 Correct 4 ms 4424 KB Output is correct
22 Correct 87 ms 6936 KB Output is correct
23 Correct 93 ms 6944 KB Output is correct
24 Correct 65 ms 6188 KB Output is correct
25 Correct 85 ms 7192 KB Output is correct
26 Correct 88 ms 7084 KB Output is correct
27 Correct 2 ms 4408 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 3 ms 4412 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Correct 5 ms 4436 KB Output is correct
32 Correct 3 ms 4396 KB Output is correct
33 Correct 2 ms 4308 KB Output is correct
34 Correct 78 ms 7356 KB Output is correct
35 Correct 76 ms 6804 KB Output is correct
36 Correct 84 ms 7228 KB Output is correct
37 Correct 78 ms 7756 KB Output is correct
38 Correct 68 ms 7216 KB Output is correct
39 Correct 40 ms 6024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4408 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4408 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 96 ms 6276 KB Output is correct
12 Correct 58 ms 5876 KB Output is correct
13 Correct 69 ms 6536 KB Output is correct
14 Correct 86 ms 6796 KB Output is correct
15 Correct 84 ms 6500 KB Output is correct
16 Correct 83 ms 6660 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 2 ms 4408 KB Output is correct
19 Correct 3 ms 4436 KB Output is correct
20 Correct 3 ms 4404 KB Output is correct
21 Correct 4 ms 4424 KB Output is correct
22 Correct 87 ms 6936 KB Output is correct
23 Correct 93 ms 6944 KB Output is correct
24 Correct 65 ms 6188 KB Output is correct
25 Correct 85 ms 7192 KB Output is correct
26 Correct 88 ms 7084 KB Output is correct
27 Correct 2 ms 4408 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 3 ms 4412 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Correct 5 ms 4436 KB Output is correct
32 Correct 3 ms 4396 KB Output is correct
33 Correct 2 ms 4308 KB Output is correct
34 Correct 78 ms 7356 KB Output is correct
35 Correct 76 ms 6804 KB Output is correct
36 Correct 84 ms 7228 KB Output is correct
37 Correct 78 ms 7756 KB Output is correct
38 Correct 68 ms 7216 KB Output is correct
39 Correct 40 ms 6024 KB Output is correct
40 Correct 4 ms 4436 KB Output is correct
41 Correct 4 ms 4424 KB Output is correct
42 Correct 4 ms 4436 KB Output is correct
43 Correct 4 ms 4424 KB Output is correct
44 Correct 82 ms 8140 KB Output is correct
45 Correct 79 ms 8068 KB Output is correct
46 Correct 80 ms 7628 KB Output is correct
47 Correct 81 ms 8156 KB Output is correct
48 Correct 68 ms 8012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4412 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 3 ms 4412 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Runtime error 6 ms 8660 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -