답안 #963841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963841 2024-04-15T19:25:27 Z RaresFelix Team Contest (JOI22_team) C++17
100 / 100
105 ms 24452 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
#define int ll
using ll = long long;
using ld = long double;  // or double, if TL is tight
using str = string; 
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

struct om {
    int x, y, z;
};

struct AIB { /// maxim pe prefix
    int n;
    vi V;
    AIB(int N) : n(N + 1), V(N + 1, -1) {}

    void update(int p, int v) {
        ++p;
        while(p < n) {
            V[p] = max(V[p], v);
            p += p & -p;
        }
    }

    int query(int p) {
        int re = -1;
        ++p;
        while(p) {
            re = max(re, V[p]);
            p -= p & -p;
        }
        return re;
    }
};

struct Plan {
    int n;
    map<int, int> MY, MZ; /// normalizari pt coordonate

    AIB MaxY, MaxZ; /// Maximele pt coordonate, dar normalizate dupa cealalta coord

    Plan(int N, map<int, int> MY0, map<int, int> MZ0) : n(N),
        MY(MY0), MZ(MZ0), MaxY(N), MaxZ(N) {}

    ll test(int y, int z) {
        ll re = -1;
        ll v1 = MaxY.query(MZ[z] - 1); 
        if(v1 == -1 || v1 <= y) return -1;
        ll v2 = MaxZ.query(MY[y] - 1);
        if(v2 == -1 || v2 <= z) return -1;
        return v1 + v2;
    }
    void insert(int y, int z) {
        /// il leg pe y cu ceva mai mic ca el
        MaxZ.update(MY[y], z);
        MaxY.update(MZ[z], y);
    }
};


signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<om> V;
    vector<pair<int, int> >  X, Y, Z;
    for(int i = 0; i < n; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        V.push_back({x, y, z});
        X.push_back({x, i});
        Y.push_back({y, i});
        Z.push_back({z, i});
    }
    sort(all(X));
    sort(all(Y));
    sort(all(Z));
    stack<int> PX, PY, PZ;
    for(auto [v, p] : X) PX.push(p);
    for(auto [v, p] : Y) PY.push(p);
    for(auto [v, p] : Z) PZ.push(p);
    vector<bool> activ(n, 1);
    while(!PX.empty() && !PY.empty() && !PZ.empty()) {
        int x = PX.top(), y = PY.top(), z = PZ.top();
        if(!activ[x]) {
            PX.pop();
            continue;
        }
        if(!activ[y]) {
            PY.pop();
            continue;
        }
        if(!activ[z]) {
            PZ.pop();
            continue;
        }

        auto [x1, y1, z1] = V[x];
        auto [x2, y2, z2] = V[y];
        auto [x3, y3, z3] = V[z];

        if(y3 == y2 || x3 == x1) {
            activ[z] = 0;
            PZ.pop();
            continue;
        }
        if(x2 == x1 || z2 == z3) {
            activ[y] = 0;
            PY.pop();
            continue;
        }
        if(y1 == y2 || z1 == z3) {
            activ[x] = 0;
            PX.pop();
            continue;
        }
        cout << x1 + y2 + z3 << "\n";
        return 0;
    }
    cout << "-1\n";
    return 0;
}

Compilation message

team.cpp: In member function 'll Plan::test(ll, ll)':
team.cpp:57:12: warning: unused variable 're' [-Wunused-variable]
   57 |         ll re = -1;
      |            ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 436 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 436 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 2 ms 984 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 3 ms 860 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 3 ms 964 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 64 ms 20120 KB Output is correct
12 Correct 43 ms 10904 KB Output is correct
13 Correct 47 ms 12952 KB Output is correct
14 Correct 72 ms 16252 KB Output is correct
15 Correct 70 ms 19912 KB Output is correct
16 Correct 48 ms 19508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 64 ms 20120 KB Output is correct
12 Correct 43 ms 10904 KB Output is correct
13 Correct 47 ms 12952 KB Output is correct
14 Correct 72 ms 16252 KB Output is correct
15 Correct 70 ms 19912 KB Output is correct
16 Correct 48 ms 19508 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 78 ms 18492 KB Output is correct
23 Correct 79 ms 20756 KB Output is correct
24 Correct 54 ms 11772 KB Output is correct
25 Correct 80 ms 16516 KB Output is correct
26 Correct 64 ms 17632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 64 ms 20120 KB Output is correct
12 Correct 43 ms 10904 KB Output is correct
13 Correct 47 ms 12952 KB Output is correct
14 Correct 72 ms 16252 KB Output is correct
15 Correct 70 ms 19912 KB Output is correct
16 Correct 48 ms 19508 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 78 ms 18492 KB Output is correct
23 Correct 79 ms 20756 KB Output is correct
24 Correct 54 ms 11772 KB Output is correct
25 Correct 80 ms 16516 KB Output is correct
26 Correct 64 ms 17632 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 70 ms 20336 KB Output is correct
35 Correct 72 ms 19828 KB Output is correct
36 Correct 79 ms 17068 KB Output is correct
37 Correct 78 ms 19324 KB Output is correct
38 Correct 67 ms 20072 KB Output is correct
39 Correct 35 ms 10652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 64 ms 20120 KB Output is correct
12 Correct 43 ms 10904 KB Output is correct
13 Correct 47 ms 12952 KB Output is correct
14 Correct 72 ms 16252 KB Output is correct
15 Correct 70 ms 19912 KB Output is correct
16 Correct 48 ms 19508 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 78 ms 18492 KB Output is correct
23 Correct 79 ms 20756 KB Output is correct
24 Correct 54 ms 11772 KB Output is correct
25 Correct 80 ms 16516 KB Output is correct
26 Correct 64 ms 17632 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 70 ms 20336 KB Output is correct
35 Correct 72 ms 19828 KB Output is correct
36 Correct 79 ms 17068 KB Output is correct
37 Correct 78 ms 19324 KB Output is correct
38 Correct 67 ms 20072 KB Output is correct
39 Correct 35 ms 10652 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 2 ms 960 KB Output is correct
44 Correct 80 ms 18896 KB Output is correct
45 Correct 91 ms 21072 KB Output is correct
46 Correct 79 ms 17632 KB Output is correct
47 Correct 83 ms 20388 KB Output is correct
48 Correct 69 ms 19004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 436 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 2 ms 984 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 3 ms 860 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 3 ms 964 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 64 ms 20120 KB Output is correct
51 Correct 43 ms 10904 KB Output is correct
52 Correct 47 ms 12952 KB Output is correct
53 Correct 72 ms 16252 KB Output is correct
54 Correct 70 ms 19912 KB Output is correct
55 Correct 48 ms 19508 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 78 ms 18492 KB Output is correct
62 Correct 79 ms 20756 KB Output is correct
63 Correct 54 ms 11772 KB Output is correct
64 Correct 80 ms 16516 KB Output is correct
65 Correct 64 ms 17632 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 2 ms 860 KB Output is correct
71 Correct 1 ms 460 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 70 ms 20336 KB Output is correct
74 Correct 72 ms 19828 KB Output is correct
75 Correct 79 ms 17068 KB Output is correct
76 Correct 78 ms 19324 KB Output is correct
77 Correct 67 ms 20072 KB Output is correct
78 Correct 35 ms 10652 KB Output is correct
79 Correct 1 ms 860 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 1 ms 860 KB Output is correct
82 Correct 2 ms 960 KB Output is correct
83 Correct 80 ms 18896 KB Output is correct
84 Correct 91 ms 21072 KB Output is correct
85 Correct 79 ms 17632 KB Output is correct
86 Correct 83 ms 20388 KB Output is correct
87 Correct 69 ms 19004 KB Output is correct
88 Correct 77 ms 19816 KB Output is correct
89 Correct 86 ms 21108 KB Output is correct
90 Correct 86 ms 24452 KB Output is correct
91 Correct 105 ms 22900 KB Output is correct
92 Correct 97 ms 22284 KB Output is correct
93 Correct 87 ms 23220 KB Output is correct
94 Correct 83 ms 19312 KB Output is correct
95 Correct 77 ms 22608 KB Output is correct
96 Correct 94 ms 19728 KB Output is correct
97 Correct 57 ms 19592 KB Output is correct
98 Correct 53 ms 21832 KB Output is correct
99 Correct 81 ms 21152 KB Output is correct