Submission #567831

# Submission time Handle Problem Language Result Execution time Memory
567831 2022-05-24T08:58:22 Z hoanghq2004 Team Contest (JOI22_team) C++14
100 / 100
1942 ms 61816 KB
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 15e4 + 10;

int n;

struct dta {
    int x, y, z;
    int operator < (const dta& other) const {
        return z > other.z;
    }
} A[N];

struct SegmentTree {
    int st[N * 4];
    SegmentTree() {
        memset(st, -1, sizeof(st));
    }
    void reset() {
        memset(st, -1, sizeof(st));
    }
    void add(int id, int L, int R, int i, int val) {
        if (L == R) {
            st[id] = max(st[id], val);
            return;
        }
        int mid = L + R >> 1;
        if (i <= mid) add(id * 2, L, mid, i, val);
        else add(id * 2 + 1, mid + 1, R, i, val);
        st[id] = max(st[id * 2], st[id * 2 + 1]);
    }
    int get(int id, int L, int R, int k) {
        if (st[id] <= k) return -1;
        if (L == R) return L;
        int mid = L + R >> 1;
        int ans = get(id * 2, L, mid, k);
        if (ans == -1) ans = get(id * 2 + 1, mid + 1, R, k);
        return ans;
    }
} ST[2];

struct RangeTree {
    vector <int> BIT[N];
    vector <int> dta[N];
    void fake_add(int x, int y) {
        ++x, ++y;
        for (; x < N; x += x & - x)
            dta[x].push_back(y);
    }
    void build() {
        for (int i = 0; i < N; ++i) sort(dta[i].begin(), dta[i].end()), BIT[i].assign(dta[i].size() + 10, 1e9);
    }
    void add(int x, int y, int w) {
        ++x, ++y;
        for (; x < N; x += x & - x) {
            int z = lower_bound(dta[x].begin(), dta[x].end(), y) - dta[x].begin() + 1;
            for (; z < BIT[x].size(); z += z & - z)
                BIT[x][z] = min(BIT[x][z], w);
        }
    }
    int get(int x, int y) {
        ++x, ++y;
        int ans = 1e9;
        for (; x; x -= x & - x) {
            int z = upper_bound(dta[x].begin(), dta[x].end(), y) - dta[x].begin();
            for (; z; z -= z & - z)
                ans = min(ans, BIT[x][z]);
        }
        return ans;
    }
} T;

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    vector <int> X, Y;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i].x >> A[i].y >> A[i].z;
        A[i].x = - A[i].x, A[i].y = - A[i].y, A[i].z = - A[i].z;
    }
    for (int i = 0; i < n; ++i) X.push_back(A[i].x), Y.push_back(A[i].y);
    sort(A, A + n);
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    for (int i = 0; i < n; ++i) {
        A[i].x = lower_bound(X.begin(), X.end(), A[i].x) - X.begin();
        A[i].y = lower_bound(Y.begin(), Y.end(), A[i].y) - Y.begin();
    }
    for (int i = 0; i < n; ++i) {
        int x = ST[0].get(1, 0, X.size() - 1, A[i].y);
        int y = ST[1].get(1, 0, Y.size() - 1, A[i].x);
        if (x != -1 && x < A[i].x) T.fake_add(x, A[i].y);
        if (y != -1 && y < A[i].y) T.fake_add(A[i].x, y);
        ST[0].add(1, 0, X.size() - 1, A[i].x, A[i].y);
        ST[1].add(1, 0, Y.size() - 1, A[i].y, A[i].x);
    }
    ST[0].reset(), ST[1].reset();
    T.build();
    int ans = 1e9;
    for (int i = 0; i < n;) {
        int j = i;
        while (j < n && A[i].z == A[j].z) ++j;
        for (int k = i; k < j; ++k) {
            ans = min(ans, A[k].z + T.get(A[k].x - 1, A[k].y - 1));
        }
        for (int k = i; k < j; ++k) {
            int x = ST[0].get(1, 0, X.size() - 1, A[k].y);
            int y = ST[1].get(1, 0, Y.size() - 1, A[k].x);
            if (x != -1 && x < A[k].x) T.add(x, A[k].y, X[x] + Y[A[k].y]);
            if (y != -1 && y < A[k].y) T.add(A[k].x, y, X[A[k].x] + Y[y]);
            ST[0].add(1, 0, X.size() - 1, A[k].x, A[k].y);
            ST[1].add(1, 0, Y.size() - 1, A[k].y, A[k].x);
        }
        i = j;
    }
    if (ans > 0) ans = 1;
    cout << - ans;
}

Compilation message

team.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
team.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
team.cpp: In member function 'void SegmentTree::add(int, int, int, int, int)':
team.cpp:37:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |         int mid = L + R >> 1;
      |                   ~~^~~
team.cpp: In member function 'int SegmentTree::get(int, int, int, int)':
team.cpp:45:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |         int mid = L + R >> 1;
      |                   ~~^~~
team.cpp: In member function 'void RangeTree::add(int, int, int)':
team.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for (; z < BIT[x].size(); z += z & - z)
      |                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19028 KB Output is correct
2 Correct 15 ms 19028 KB Output is correct
3 Correct 19 ms 19028 KB Output is correct
4 Correct 16 ms 19008 KB Output is correct
5 Correct 18 ms 19028 KB Output is correct
6 Correct 19 ms 19112 KB Output is correct
7 Correct 16 ms 19036 KB Output is correct
8 Correct 16 ms 19000 KB Output is correct
9 Correct 19 ms 19028 KB Output is correct
10 Correct 16 ms 19112 KB Output is correct
11 Correct 17 ms 19028 KB Output is correct
12 Correct 14 ms 19028 KB Output is correct
13 Correct 15 ms 19100 KB Output is correct
14 Correct 16 ms 19228 KB Output is correct
15 Correct 16 ms 19156 KB Output is correct
16 Correct 20 ms 19084 KB Output is correct
17 Correct 16 ms 19132 KB Output is correct
18 Correct 19 ms 19204 KB Output is correct
19 Correct 16 ms 19156 KB Output is correct
20 Correct 19 ms 19156 KB Output is correct
21 Correct 16 ms 19060 KB Output is correct
22 Correct 15 ms 19092 KB Output is correct
23 Correct 15 ms 19100 KB Output is correct
24 Correct 15 ms 19120 KB Output is correct
25 Correct 16 ms 19132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19028 KB Output is correct
2 Correct 15 ms 19028 KB Output is correct
3 Correct 19 ms 19028 KB Output is correct
4 Correct 16 ms 19008 KB Output is correct
5 Correct 18 ms 19028 KB Output is correct
6 Correct 19 ms 19112 KB Output is correct
7 Correct 16 ms 19036 KB Output is correct
8 Correct 16 ms 19000 KB Output is correct
9 Correct 19 ms 19028 KB Output is correct
10 Correct 16 ms 19112 KB Output is correct
11 Correct 17 ms 19028 KB Output is correct
12 Correct 14 ms 19028 KB Output is correct
13 Correct 15 ms 19100 KB Output is correct
14 Correct 16 ms 19228 KB Output is correct
15 Correct 16 ms 19156 KB Output is correct
16 Correct 20 ms 19084 KB Output is correct
17 Correct 16 ms 19132 KB Output is correct
18 Correct 19 ms 19204 KB Output is correct
19 Correct 16 ms 19156 KB Output is correct
20 Correct 19 ms 19156 KB Output is correct
21 Correct 16 ms 19060 KB Output is correct
22 Correct 15 ms 19092 KB Output is correct
23 Correct 15 ms 19100 KB Output is correct
24 Correct 15 ms 19120 KB Output is correct
25 Correct 16 ms 19132 KB Output is correct
26 Correct 38 ms 20272 KB Output is correct
27 Correct 32 ms 19956 KB Output is correct
28 Correct 35 ms 19828 KB Output is correct
29 Correct 24 ms 19512 KB Output is correct
30 Correct 22 ms 19668 KB Output is correct
31 Correct 34 ms 19896 KB Output is correct
32 Correct 23 ms 19592 KB Output is correct
33 Correct 21 ms 19412 KB Output is correct
34 Correct 25 ms 19156 KB Output is correct
35 Correct 16 ms 19028 KB Output is correct
36 Correct 22 ms 19028 KB Output is correct
37 Correct 19 ms 19156 KB Output is correct
38 Correct 21 ms 19156 KB Output is correct
39 Correct 23 ms 19540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19124 KB Output is correct
2 Correct 15 ms 19036 KB Output is correct
3 Correct 15 ms 19032 KB Output is correct
4 Correct 16 ms 19028 KB Output is correct
5 Correct 16 ms 19024 KB Output is correct
6 Correct 16 ms 19036 KB Output is correct
7 Correct 16 ms 19036 KB Output is correct
8 Correct 15 ms 19012 KB Output is correct
9 Correct 18 ms 19112 KB Output is correct
10 Correct 14 ms 19028 KB Output is correct
11 Correct 417 ms 45264 KB Output is correct
12 Correct 147 ms 28260 KB Output is correct
13 Correct 95 ms 23648 KB Output is correct
14 Correct 302 ms 39200 KB Output is correct
15 Correct 290 ms 34812 KB Output is correct
16 Correct 81 ms 22592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19124 KB Output is correct
2 Correct 15 ms 19036 KB Output is correct
3 Correct 15 ms 19032 KB Output is correct
4 Correct 16 ms 19028 KB Output is correct
5 Correct 16 ms 19024 KB Output is correct
6 Correct 16 ms 19036 KB Output is correct
7 Correct 16 ms 19036 KB Output is correct
8 Correct 15 ms 19012 KB Output is correct
9 Correct 18 ms 19112 KB Output is correct
10 Correct 14 ms 19028 KB Output is correct
11 Correct 417 ms 45264 KB Output is correct
12 Correct 147 ms 28260 KB Output is correct
13 Correct 95 ms 23648 KB Output is correct
14 Correct 302 ms 39200 KB Output is correct
15 Correct 290 ms 34812 KB Output is correct
16 Correct 81 ms 22592 KB Output is correct
17 Correct 17 ms 19028 KB Output is correct
18 Correct 15 ms 19028 KB Output is correct
19 Correct 15 ms 19004 KB Output is correct
20 Correct 22 ms 19124 KB Output is correct
21 Correct 26 ms 19636 KB Output is correct
22 Correct 691 ms 55724 KB Output is correct
23 Correct 354 ms 40172 KB Output is correct
24 Correct 198 ms 33036 KB Output is correct
25 Correct 279 ms 36304 KB Output is correct
26 Correct 214 ms 35292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19124 KB Output is correct
2 Correct 15 ms 19036 KB Output is correct
3 Correct 15 ms 19032 KB Output is correct
4 Correct 16 ms 19028 KB Output is correct
5 Correct 16 ms 19024 KB Output is correct
6 Correct 16 ms 19036 KB Output is correct
7 Correct 16 ms 19036 KB Output is correct
8 Correct 15 ms 19012 KB Output is correct
9 Correct 18 ms 19112 KB Output is correct
10 Correct 14 ms 19028 KB Output is correct
11 Correct 417 ms 45264 KB Output is correct
12 Correct 147 ms 28260 KB Output is correct
13 Correct 95 ms 23648 KB Output is correct
14 Correct 302 ms 39200 KB Output is correct
15 Correct 290 ms 34812 KB Output is correct
16 Correct 81 ms 22592 KB Output is correct
17 Correct 17 ms 19028 KB Output is correct
18 Correct 15 ms 19028 KB Output is correct
19 Correct 15 ms 19004 KB Output is correct
20 Correct 22 ms 19124 KB Output is correct
21 Correct 26 ms 19636 KB Output is correct
22 Correct 691 ms 55724 KB Output is correct
23 Correct 354 ms 40172 KB Output is correct
24 Correct 198 ms 33036 KB Output is correct
25 Correct 279 ms 36304 KB Output is correct
26 Correct 214 ms 35292 KB Output is correct
27 Correct 16 ms 19116 KB Output is correct
28 Correct 15 ms 19200 KB Output is correct
29 Correct 15 ms 19012 KB Output is correct
30 Correct 20 ms 19048 KB Output is correct
31 Correct 27 ms 19620 KB Output is correct
32 Correct 16 ms 19124 KB Output is correct
33 Correct 21 ms 19028 KB Output is correct
34 Correct 1485 ms 57848 KB Output is correct
35 Correct 611 ms 40900 KB Output is correct
36 Correct 674 ms 42564 KB Output is correct
37 Correct 392 ms 36232 KB Output is correct
38 Correct 254 ms 35236 KB Output is correct
39 Correct 87 ms 21536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19124 KB Output is correct
2 Correct 15 ms 19036 KB Output is correct
3 Correct 15 ms 19032 KB Output is correct
4 Correct 16 ms 19028 KB Output is correct
5 Correct 16 ms 19024 KB Output is correct
6 Correct 16 ms 19036 KB Output is correct
7 Correct 16 ms 19036 KB Output is correct
8 Correct 15 ms 19012 KB Output is correct
9 Correct 18 ms 19112 KB Output is correct
10 Correct 14 ms 19028 KB Output is correct
11 Correct 417 ms 45264 KB Output is correct
12 Correct 147 ms 28260 KB Output is correct
13 Correct 95 ms 23648 KB Output is correct
14 Correct 302 ms 39200 KB Output is correct
15 Correct 290 ms 34812 KB Output is correct
16 Correct 81 ms 22592 KB Output is correct
17 Correct 17 ms 19028 KB Output is correct
18 Correct 15 ms 19028 KB Output is correct
19 Correct 15 ms 19004 KB Output is correct
20 Correct 22 ms 19124 KB Output is correct
21 Correct 26 ms 19636 KB Output is correct
22 Correct 691 ms 55724 KB Output is correct
23 Correct 354 ms 40172 KB Output is correct
24 Correct 198 ms 33036 KB Output is correct
25 Correct 279 ms 36304 KB Output is correct
26 Correct 214 ms 35292 KB Output is correct
27 Correct 16 ms 19116 KB Output is correct
28 Correct 15 ms 19200 KB Output is correct
29 Correct 15 ms 19012 KB Output is correct
30 Correct 20 ms 19048 KB Output is correct
31 Correct 27 ms 19620 KB Output is correct
32 Correct 16 ms 19124 KB Output is correct
33 Correct 21 ms 19028 KB Output is correct
34 Correct 1485 ms 57848 KB Output is correct
35 Correct 611 ms 40900 KB Output is correct
36 Correct 674 ms 42564 KB Output is correct
37 Correct 392 ms 36232 KB Output is correct
38 Correct 254 ms 35236 KB Output is correct
39 Correct 87 ms 21536 KB Output is correct
40 Correct 25 ms 19568 KB Output is correct
41 Correct 33 ms 19988 KB Output is correct
42 Correct 20 ms 19172 KB Output is correct
43 Correct 19 ms 19132 KB Output is correct
44 Correct 1923 ms 60624 KB Output is correct
45 Correct 525 ms 38080 KB Output is correct
46 Correct 678 ms 40640 KB Output is correct
47 Correct 464 ms 36692 KB Output is correct
48 Correct 280 ms 36408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19028 KB Output is correct
2 Correct 15 ms 19028 KB Output is correct
3 Correct 19 ms 19028 KB Output is correct
4 Correct 16 ms 19008 KB Output is correct
5 Correct 18 ms 19028 KB Output is correct
6 Correct 19 ms 19112 KB Output is correct
7 Correct 16 ms 19036 KB Output is correct
8 Correct 16 ms 19000 KB Output is correct
9 Correct 19 ms 19028 KB Output is correct
10 Correct 16 ms 19112 KB Output is correct
11 Correct 17 ms 19028 KB Output is correct
12 Correct 14 ms 19028 KB Output is correct
13 Correct 15 ms 19100 KB Output is correct
14 Correct 16 ms 19228 KB Output is correct
15 Correct 16 ms 19156 KB Output is correct
16 Correct 20 ms 19084 KB Output is correct
17 Correct 16 ms 19132 KB Output is correct
18 Correct 19 ms 19204 KB Output is correct
19 Correct 16 ms 19156 KB Output is correct
20 Correct 19 ms 19156 KB Output is correct
21 Correct 16 ms 19060 KB Output is correct
22 Correct 15 ms 19092 KB Output is correct
23 Correct 15 ms 19100 KB Output is correct
24 Correct 15 ms 19120 KB Output is correct
25 Correct 16 ms 19132 KB Output is correct
26 Correct 38 ms 20272 KB Output is correct
27 Correct 32 ms 19956 KB Output is correct
28 Correct 35 ms 19828 KB Output is correct
29 Correct 24 ms 19512 KB Output is correct
30 Correct 22 ms 19668 KB Output is correct
31 Correct 34 ms 19896 KB Output is correct
32 Correct 23 ms 19592 KB Output is correct
33 Correct 21 ms 19412 KB Output is correct
34 Correct 25 ms 19156 KB Output is correct
35 Correct 16 ms 19028 KB Output is correct
36 Correct 22 ms 19028 KB Output is correct
37 Correct 19 ms 19156 KB Output is correct
38 Correct 21 ms 19156 KB Output is correct
39 Correct 23 ms 19540 KB Output is correct
40 Correct 15 ms 19124 KB Output is correct
41 Correct 15 ms 19036 KB Output is correct
42 Correct 15 ms 19032 KB Output is correct
43 Correct 16 ms 19028 KB Output is correct
44 Correct 16 ms 19024 KB Output is correct
45 Correct 16 ms 19036 KB Output is correct
46 Correct 16 ms 19036 KB Output is correct
47 Correct 15 ms 19012 KB Output is correct
48 Correct 18 ms 19112 KB Output is correct
49 Correct 14 ms 19028 KB Output is correct
50 Correct 417 ms 45264 KB Output is correct
51 Correct 147 ms 28260 KB Output is correct
52 Correct 95 ms 23648 KB Output is correct
53 Correct 302 ms 39200 KB Output is correct
54 Correct 290 ms 34812 KB Output is correct
55 Correct 81 ms 22592 KB Output is correct
56 Correct 17 ms 19028 KB Output is correct
57 Correct 15 ms 19028 KB Output is correct
58 Correct 15 ms 19004 KB Output is correct
59 Correct 22 ms 19124 KB Output is correct
60 Correct 26 ms 19636 KB Output is correct
61 Correct 691 ms 55724 KB Output is correct
62 Correct 354 ms 40172 KB Output is correct
63 Correct 198 ms 33036 KB Output is correct
64 Correct 279 ms 36304 KB Output is correct
65 Correct 214 ms 35292 KB Output is correct
66 Correct 16 ms 19116 KB Output is correct
67 Correct 15 ms 19200 KB Output is correct
68 Correct 15 ms 19012 KB Output is correct
69 Correct 20 ms 19048 KB Output is correct
70 Correct 27 ms 19620 KB Output is correct
71 Correct 16 ms 19124 KB Output is correct
72 Correct 21 ms 19028 KB Output is correct
73 Correct 1485 ms 57848 KB Output is correct
74 Correct 611 ms 40900 KB Output is correct
75 Correct 674 ms 42564 KB Output is correct
76 Correct 392 ms 36232 KB Output is correct
77 Correct 254 ms 35236 KB Output is correct
78 Correct 87 ms 21536 KB Output is correct
79 Correct 25 ms 19568 KB Output is correct
80 Correct 33 ms 19988 KB Output is correct
81 Correct 20 ms 19172 KB Output is correct
82 Correct 19 ms 19132 KB Output is correct
83 Correct 1923 ms 60624 KB Output is correct
84 Correct 525 ms 38080 KB Output is correct
85 Correct 678 ms 40640 KB Output is correct
86 Correct 464 ms 36692 KB Output is correct
87 Correct 280 ms 36408 KB Output is correct
88 Correct 1942 ms 61816 KB Output is correct
89 Correct 726 ms 40856 KB Output is correct
90 Correct 1330 ms 53492 KB Output is correct
91 Correct 454 ms 32732 KB Output is correct
92 Correct 1146 ms 46588 KB Output is correct
93 Correct 623 ms 39348 KB Output is correct
94 Correct 521 ms 35512 KB Output is correct
95 Correct 280 ms 38260 KB Output is correct
96 Correct 219 ms 25600 KB Output is correct
97 Correct 103 ms 24712 KB Output is correct
98 Correct 156 ms 24528 KB Output is correct
99 Correct 194 ms 24396 KB Output is correct