Submission #553759

# Submission time Handle Problem Language Result Execution time Memory
553759 2022-04-26T20:31:43 Z LucaDantas Team Contest (JOI22_team) C++17
100 / 100
254 ms 17356 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;

int back[maxn];
map<int,int> mp;

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(back[x2] > x && y2 > y) aq = max(aq, back[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};
        mp[x] = 0;
    }
    int coord = 0;
    for(auto& it : mp)
        it.second = ++coord, back[coord] = it.first;
    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(mp[pt[j].x], pt[j].y);
        for(j = i; j < n && pt[i].z == pt[j].z; j++)
            st.calc(mp[pt[j].x], pt[j].y);
    }
    printf("%d\n", ans);
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:71:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     int n; scanf("%d", &n);
      |            ~~~~~^~~~~~~~~~
team.cpp:73:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         int x, y, z; scanf("%d %d %d", &x, &y, &z);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 4308 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 2 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 Correct 3 ms 4436 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 3 ms 4436 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 3 ms 4436 KB Output is correct
19 Correct 2 ms 4308 KB Output is correct
20 Correct 2 ms 4424 KB Output is correct
21 Correct 2 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 4308 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 2 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 Correct 3 ms 4436 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 3 ms 4436 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 3 ms 4436 KB Output is correct
19 Correct 2 ms 4308 KB Output is correct
20 Correct 2 ms 4424 KB Output is correct
21 Correct 2 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4356 KB Output is correct
26 Correct 6 ms 4704 KB Output is correct
27 Correct 6 ms 4540 KB Output is correct
28 Correct 6 ms 4564 KB Output is correct
29 Correct 6 ms 4520 KB Output is correct
30 Correct 4 ms 4436 KB Output is correct
31 Correct 5 ms 4436 KB Output is correct
32 Correct 5 ms 4436 KB Output is correct
33 Correct 6 ms 4564 KB Output is correct
34 Correct 6 ms 4732 KB Output is correct
35 Correct 3 ms 4436 KB Output is correct
36 Correct 3 ms 4428 KB Output is correct
37 Correct 5 ms 4556 KB Output is correct
38 Correct 5 ms 4564 KB Output is correct
39 Correct 4 ms 4420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 3 ms 4308 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 97 ms 6168 KB Output is correct
12 Correct 66 ms 5696 KB Output is correct
13 Correct 73 ms 5968 KB Output is correct
14 Correct 92 ms 6280 KB Output is correct
15 Correct 91 ms 6280 KB Output is correct
16 Correct 81 ms 6280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 3 ms 4308 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 97 ms 6168 KB Output is correct
12 Correct 66 ms 5696 KB Output is correct
13 Correct 73 ms 5968 KB Output is correct
14 Correct 92 ms 6280 KB Output is correct
15 Correct 91 ms 6280 KB Output is correct
16 Correct 81 ms 6280 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 3 ms 4308 KB Output is correct
20 Correct 3 ms 4308 KB Output is correct
21 Correct 4 ms 4436 KB Output is correct
22 Correct 96 ms 6220 KB Output is correct
23 Correct 93 ms 6240 KB Output is correct
24 Correct 71 ms 5792 KB Output is correct
25 Correct 95 ms 6244 KB Output is correct
26 Correct 87 ms 6276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 3 ms 4308 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 97 ms 6168 KB Output is correct
12 Correct 66 ms 5696 KB Output is correct
13 Correct 73 ms 5968 KB Output is correct
14 Correct 92 ms 6280 KB Output is correct
15 Correct 91 ms 6280 KB Output is correct
16 Correct 81 ms 6280 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 3 ms 4308 KB Output is correct
20 Correct 3 ms 4308 KB Output is correct
21 Correct 4 ms 4436 KB Output is correct
22 Correct 96 ms 6220 KB Output is correct
23 Correct 93 ms 6240 KB Output is correct
24 Correct 71 ms 5792 KB Output is correct
25 Correct 95 ms 6244 KB Output is correct
26 Correct 87 ms 6276 KB Output is correct
27 Correct 2 ms 4436 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 2 ms 4308 KB Output is correct
30 Correct 2 ms 4368 KB Output is correct
31 Correct 5 ms 4436 KB Output is correct
32 Correct 3 ms 4436 KB Output is correct
33 Correct 3 ms 4436 KB Output is correct
34 Correct 87 ms 6092 KB Output is correct
35 Correct 86 ms 6032 KB Output is correct
36 Correct 98 ms 6228 KB Output is correct
37 Correct 92 ms 6228 KB Output is correct
38 Correct 74 ms 6252 KB Output is correct
39 Correct 53 ms 5492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 3 ms 4308 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 97 ms 6168 KB Output is correct
12 Correct 66 ms 5696 KB Output is correct
13 Correct 73 ms 5968 KB Output is correct
14 Correct 92 ms 6280 KB Output is correct
15 Correct 91 ms 6280 KB Output is correct
16 Correct 81 ms 6280 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 3 ms 4308 KB Output is correct
20 Correct 3 ms 4308 KB Output is correct
21 Correct 4 ms 4436 KB Output is correct
22 Correct 96 ms 6220 KB Output is correct
23 Correct 93 ms 6240 KB Output is correct
24 Correct 71 ms 5792 KB Output is correct
25 Correct 95 ms 6244 KB Output is correct
26 Correct 87 ms 6276 KB Output is correct
27 Correct 2 ms 4436 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 2 ms 4308 KB Output is correct
30 Correct 2 ms 4368 KB Output is correct
31 Correct 5 ms 4436 KB Output is correct
32 Correct 3 ms 4436 KB Output is correct
33 Correct 3 ms 4436 KB Output is correct
34 Correct 87 ms 6092 KB Output is correct
35 Correct 86 ms 6032 KB Output is correct
36 Correct 98 ms 6228 KB Output is correct
37 Correct 92 ms 6228 KB Output is correct
38 Correct 74 ms 6252 KB Output is correct
39 Correct 53 ms 5492 KB Output is correct
40 Correct 4 ms 4564 KB Output is correct
41 Correct 5 ms 4564 KB Output is correct
42 Correct 5 ms 4436 KB Output is correct
43 Correct 5 ms 4564 KB Output is correct
44 Correct 122 ms 6460 KB Output is correct
45 Correct 115 ms 6460 KB Output is correct
46 Correct 119 ms 6476 KB Output is correct
47 Correct 109 ms 6476 KB Output is correct
48 Correct 82 ms 6268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 4308 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 2 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 Correct 3 ms 4436 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 3 ms 4436 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 3 ms 4436 KB Output is correct
19 Correct 2 ms 4308 KB Output is correct
20 Correct 2 ms 4424 KB Output is correct
21 Correct 2 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4356 KB Output is correct
26 Correct 6 ms 4704 KB Output is correct
27 Correct 6 ms 4540 KB Output is correct
28 Correct 6 ms 4564 KB Output is correct
29 Correct 6 ms 4520 KB Output is correct
30 Correct 4 ms 4436 KB Output is correct
31 Correct 5 ms 4436 KB Output is correct
32 Correct 5 ms 4436 KB Output is correct
33 Correct 6 ms 4564 KB Output is correct
34 Correct 6 ms 4732 KB Output is correct
35 Correct 3 ms 4436 KB Output is correct
36 Correct 3 ms 4428 KB Output is correct
37 Correct 5 ms 4556 KB Output is correct
38 Correct 5 ms 4564 KB Output is correct
39 Correct 4 ms 4420 KB Output is correct
40 Correct 2 ms 4308 KB Output is correct
41 Correct 2 ms 4308 KB Output is correct
42 Correct 2 ms 4308 KB Output is correct
43 Correct 2 ms 4308 KB Output is correct
44 Correct 2 ms 4308 KB Output is correct
45 Correct 2 ms 4308 KB Output is correct
46 Correct 3 ms 4308 KB Output is correct
47 Correct 2 ms 4308 KB Output is correct
48 Correct 2 ms 4308 KB Output is correct
49 Correct 2 ms 4308 KB Output is correct
50 Correct 97 ms 6168 KB Output is correct
51 Correct 66 ms 5696 KB Output is correct
52 Correct 73 ms 5968 KB Output is correct
53 Correct 92 ms 6280 KB Output is correct
54 Correct 91 ms 6280 KB Output is correct
55 Correct 81 ms 6280 KB Output is correct
56 Correct 2 ms 4308 KB Output is correct
57 Correct 3 ms 4308 KB Output is correct
58 Correct 3 ms 4308 KB Output is correct
59 Correct 3 ms 4308 KB Output is correct
60 Correct 4 ms 4436 KB Output is correct
61 Correct 96 ms 6220 KB Output is correct
62 Correct 93 ms 6240 KB Output is correct
63 Correct 71 ms 5792 KB Output is correct
64 Correct 95 ms 6244 KB Output is correct
65 Correct 87 ms 6276 KB Output is correct
66 Correct 2 ms 4436 KB Output is correct
67 Correct 2 ms 4308 KB Output is correct
68 Correct 2 ms 4308 KB Output is correct
69 Correct 2 ms 4368 KB Output is correct
70 Correct 5 ms 4436 KB Output is correct
71 Correct 3 ms 4436 KB Output is correct
72 Correct 3 ms 4436 KB Output is correct
73 Correct 87 ms 6092 KB Output is correct
74 Correct 86 ms 6032 KB Output is correct
75 Correct 98 ms 6228 KB Output is correct
76 Correct 92 ms 6228 KB Output is correct
77 Correct 74 ms 6252 KB Output is correct
78 Correct 53 ms 5492 KB Output is correct
79 Correct 4 ms 4564 KB Output is correct
80 Correct 5 ms 4564 KB Output is correct
81 Correct 5 ms 4436 KB Output is correct
82 Correct 5 ms 4564 KB Output is correct
83 Correct 122 ms 6460 KB Output is correct
84 Correct 115 ms 6460 KB Output is correct
85 Correct 119 ms 6476 KB Output is correct
86 Correct 109 ms 6476 KB Output is correct
87 Correct 82 ms 6268 KB Output is correct
88 Correct 254 ms 16204 KB Output is correct
89 Correct 191 ms 12452 KB Output is correct
90 Correct 230 ms 14700 KB Output is correct
91 Correct 164 ms 11104 KB Output is correct
92 Correct 149 ms 9292 KB Output is correct
93 Correct 185 ms 13372 KB Output is correct
94 Correct 159 ms 11468 KB Output is correct
95 Correct 114 ms 11780 KB Output is correct
96 Correct 165 ms 17356 KB Output is correct
97 Correct 100 ms 8632 KB Output is correct
98 Correct 112 ms 11224 KB Output is correct
99 Correct 118 ms 11068 KB Output is correct