답안 #567806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567806 2022-05-24T08:33:45 Z hoanghq2004 Team Contest (JOI22_team) C++14
37 / 100
289 ms 39476 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] = 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)
      |                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19052 KB Output is correct
2 Correct 17 ms 19028 KB Output is correct
3 Correct 16 ms 18996 KB Output is correct
4 Correct 18 ms 19068 KB Output is correct
5 Correct 17 ms 19032 KB Output is correct
6 Correct 19 ms 19048 KB Output is correct
7 Correct 19 ms 19092 KB Output is correct
8 Correct 16 ms 19096 KB Output is correct
9 Correct 19 ms 19088 KB Output is correct
10 Correct 18 ms 19000 KB Output is correct
11 Correct 16 ms 19028 KB Output is correct
12 Correct 18 ms 19188 KB Output is correct
13 Correct 17 ms 19036 KB Output is correct
14 Correct 20 ms 19236 KB Output is correct
15 Correct 17 ms 19120 KB Output is correct
16 Correct 17 ms 19136 KB Output is correct
17 Correct 18 ms 19136 KB Output is correct
18 Correct 17 ms 19184 KB Output is correct
19 Correct 17 ms 19120 KB Output is correct
20 Correct 17 ms 19160 KB Output is correct
21 Correct 16 ms 19148 KB Output is correct
22 Correct 16 ms 19028 KB Output is correct
23 Correct 16 ms 19028 KB Output is correct
24 Correct 19 ms 19028 KB Output is correct
25 Correct 15 ms 19112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19052 KB Output is correct
2 Correct 17 ms 19028 KB Output is correct
3 Correct 16 ms 18996 KB Output is correct
4 Correct 18 ms 19068 KB Output is correct
5 Correct 17 ms 19032 KB Output is correct
6 Correct 19 ms 19048 KB Output is correct
7 Correct 19 ms 19092 KB Output is correct
8 Correct 16 ms 19096 KB Output is correct
9 Correct 19 ms 19088 KB Output is correct
10 Correct 18 ms 19000 KB Output is correct
11 Correct 16 ms 19028 KB Output is correct
12 Correct 18 ms 19188 KB Output is correct
13 Correct 17 ms 19036 KB Output is correct
14 Correct 20 ms 19236 KB Output is correct
15 Correct 17 ms 19120 KB Output is correct
16 Correct 17 ms 19136 KB Output is correct
17 Correct 18 ms 19136 KB Output is correct
18 Correct 17 ms 19184 KB Output is correct
19 Correct 17 ms 19120 KB Output is correct
20 Correct 17 ms 19160 KB Output is correct
21 Correct 16 ms 19148 KB Output is correct
22 Correct 16 ms 19028 KB Output is correct
23 Correct 16 ms 19028 KB Output is correct
24 Correct 19 ms 19028 KB Output is correct
25 Correct 15 ms 19112 KB Output is correct
26 Correct 40 ms 20180 KB Output is correct
27 Correct 31 ms 20016 KB Output is correct
28 Correct 29 ms 19848 KB Output is correct
29 Correct 25 ms 19560 KB Output is correct
30 Correct 22 ms 19528 KB Output is correct
31 Correct 34 ms 19996 KB Output is correct
32 Correct 25 ms 19580 KB Output is correct
33 Correct 23 ms 19412 KB Output is correct
34 Correct 20 ms 19180 KB Output is correct
35 Correct 21 ms 19024 KB Output is correct
36 Correct 16 ms 19156 KB Output is correct
37 Correct 25 ms 19156 KB Output is correct
38 Correct 22 ms 19148 KB Output is correct
39 Correct 22 ms 19532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19028 KB Output is correct
2 Correct 15 ms 19004 KB Output is correct
3 Correct 16 ms 19000 KB Output is correct
4 Correct 15 ms 19004 KB Output is correct
5 Correct 15 ms 19028 KB Output is correct
6 Correct 16 ms 19020 KB Output is correct
7 Correct 15 ms 19028 KB Output is correct
8 Correct 16 ms 19104 KB Output is correct
9 Correct 15 ms 19112 KB Output is correct
10 Correct 15 ms 19120 KB Output is correct
11 Correct 289 ms 39476 KB Output is correct
12 Correct 128 ms 26788 KB Output is correct
13 Incorrect 90 ms 22636 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19028 KB Output is correct
2 Correct 15 ms 19004 KB Output is correct
3 Correct 16 ms 19000 KB Output is correct
4 Correct 15 ms 19004 KB Output is correct
5 Correct 15 ms 19028 KB Output is correct
6 Correct 16 ms 19020 KB Output is correct
7 Correct 15 ms 19028 KB Output is correct
8 Correct 16 ms 19104 KB Output is correct
9 Correct 15 ms 19112 KB Output is correct
10 Correct 15 ms 19120 KB Output is correct
11 Correct 289 ms 39476 KB Output is correct
12 Correct 128 ms 26788 KB Output is correct
13 Incorrect 90 ms 22636 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19028 KB Output is correct
2 Correct 15 ms 19004 KB Output is correct
3 Correct 16 ms 19000 KB Output is correct
4 Correct 15 ms 19004 KB Output is correct
5 Correct 15 ms 19028 KB Output is correct
6 Correct 16 ms 19020 KB Output is correct
7 Correct 15 ms 19028 KB Output is correct
8 Correct 16 ms 19104 KB Output is correct
9 Correct 15 ms 19112 KB Output is correct
10 Correct 15 ms 19120 KB Output is correct
11 Correct 289 ms 39476 KB Output is correct
12 Correct 128 ms 26788 KB Output is correct
13 Incorrect 90 ms 22636 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19028 KB Output is correct
2 Correct 15 ms 19004 KB Output is correct
3 Correct 16 ms 19000 KB Output is correct
4 Correct 15 ms 19004 KB Output is correct
5 Correct 15 ms 19028 KB Output is correct
6 Correct 16 ms 19020 KB Output is correct
7 Correct 15 ms 19028 KB Output is correct
8 Correct 16 ms 19104 KB Output is correct
9 Correct 15 ms 19112 KB Output is correct
10 Correct 15 ms 19120 KB Output is correct
11 Correct 289 ms 39476 KB Output is correct
12 Correct 128 ms 26788 KB Output is correct
13 Incorrect 90 ms 22636 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19052 KB Output is correct
2 Correct 17 ms 19028 KB Output is correct
3 Correct 16 ms 18996 KB Output is correct
4 Correct 18 ms 19068 KB Output is correct
5 Correct 17 ms 19032 KB Output is correct
6 Correct 19 ms 19048 KB Output is correct
7 Correct 19 ms 19092 KB Output is correct
8 Correct 16 ms 19096 KB Output is correct
9 Correct 19 ms 19088 KB Output is correct
10 Correct 18 ms 19000 KB Output is correct
11 Correct 16 ms 19028 KB Output is correct
12 Correct 18 ms 19188 KB Output is correct
13 Correct 17 ms 19036 KB Output is correct
14 Correct 20 ms 19236 KB Output is correct
15 Correct 17 ms 19120 KB Output is correct
16 Correct 17 ms 19136 KB Output is correct
17 Correct 18 ms 19136 KB Output is correct
18 Correct 17 ms 19184 KB Output is correct
19 Correct 17 ms 19120 KB Output is correct
20 Correct 17 ms 19160 KB Output is correct
21 Correct 16 ms 19148 KB Output is correct
22 Correct 16 ms 19028 KB Output is correct
23 Correct 16 ms 19028 KB Output is correct
24 Correct 19 ms 19028 KB Output is correct
25 Correct 15 ms 19112 KB Output is correct
26 Correct 40 ms 20180 KB Output is correct
27 Correct 31 ms 20016 KB Output is correct
28 Correct 29 ms 19848 KB Output is correct
29 Correct 25 ms 19560 KB Output is correct
30 Correct 22 ms 19528 KB Output is correct
31 Correct 34 ms 19996 KB Output is correct
32 Correct 25 ms 19580 KB Output is correct
33 Correct 23 ms 19412 KB Output is correct
34 Correct 20 ms 19180 KB Output is correct
35 Correct 21 ms 19024 KB Output is correct
36 Correct 16 ms 19156 KB Output is correct
37 Correct 25 ms 19156 KB Output is correct
38 Correct 22 ms 19148 KB Output is correct
39 Correct 22 ms 19532 KB Output is correct
40 Correct 15 ms 19028 KB Output is correct
41 Correct 15 ms 19004 KB Output is correct
42 Correct 16 ms 19000 KB Output is correct
43 Correct 15 ms 19004 KB Output is correct
44 Correct 15 ms 19028 KB Output is correct
45 Correct 16 ms 19020 KB Output is correct
46 Correct 15 ms 19028 KB Output is correct
47 Correct 16 ms 19104 KB Output is correct
48 Correct 15 ms 19112 KB Output is correct
49 Correct 15 ms 19120 KB Output is correct
50 Correct 289 ms 39476 KB Output is correct
51 Correct 128 ms 26788 KB Output is correct
52 Incorrect 90 ms 22636 KB Output isn't correct
53 Halted 0 ms 0 KB -