Submission #884702

# Submission time Handle Problem Language Result Execution time Memory
884702 2023-12-08T06:35:45 Z Desh03 Team Contest (JOI22_team) C++17
73 / 100
2000 ms 210984 KB
#include <bits/stdc++.h>
 
using namespace std;

void chmax(int &x, const int &y) {
    x = (x > y ? x : y);
}

struct Fenwick {
    vector<int> f;
    int n;
    Fenwick(int n_) : n(n_) {
        f.resize(n);
    }
    void upd(int i, int x) {
        while (i < n) {
            chmax(f[i], x);
            i |= i + 1;
        }
    }
    int qry(int i) {
        int x = 0;
        while (i >= 0) {
            chmax(x, f[i]);
            i = (i & i + 1) - 1;
        }
        return x;
    }
};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct Fenwick2D {
    vector<unordered_map<int, int, custom_hash>> f;
    int nx, ny;
    Fenwick2D(int nx_, int ny_) : nx(nx_), ny(ny_) {
        f.resize(nx_);
    }
    void upd(int i, int J, int x) {
        while (i >= 0) {
            for (int j = J; j >= 0; j = (j & j + 1) - 1) {
                chmax(f[i][j], x);
            }
            i = (i & i + 1) - 1;
        }
    }
    int qry(int i, int J) {
        int x = 0;
        while (i < nx) {
            for (int j = J; j < ny; j |= j + 1) {
                chmax(x, f[i][j]);
            }
            i |= i + 1;
        }
        return x;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<tuple<int, int, int>> a(n);
    vector<int> cmpx, cmpy, cmpz;
    for (auto &[x, y, z] : a) {
        cin >> x >> y >> z;
        cmpx.push_back(x);
        cmpy.push_back(y);
        cmpz.push_back(z);
    }
    sort(cmpx.begin(), cmpx.end());
    cmpx.erase(unique(cmpx.begin(), cmpx.end()), cmpx.end());
    sort(cmpy.begin(), cmpy.end());
    cmpy.erase(unique(cmpy.begin(), cmpy.end()), cmpy.end());
    sort(cmpz.begin(), cmpz.end());
    cmpz.erase(unique(cmpz.begin(), cmpz.end()), cmpz.end());
    vector<vector<pair<int, int>>> X(cmpx.size());
    for (auto &[x, y, z] : a) {
        X[lower_bound(cmpx.begin(), cmpx.end(), x) - cmpx.begin()].push_back({lower_bound(cmpy.begin(), cmpy.end(), y) - cmpy.begin(), lower_bound(cmpz.begin(), cmpz.end(), z) - cmpz.begin()});
    }
    Fenwick fy(cmpy.size()), fz(cmpz.size());
    Fenwick2D fyz(cmpy.size(), cmpz.size());
    int ans = -1;
    for (int x = 0; x < cmpx.size(); x++) {
        for (auto &[y, z] : X[x]) {
            int wyz = fyz.qry(y + 1, z + 1);
            if (wyz) chmax(ans, cmpx[x] + wyz);
        }
        for (auto &[y, z] : X[x]) {
            int wz = fy.qry(y - 1), wy = fz.qry(z - 1);
            if (wz > z) fyz.upd(y, wz, cmpy[y] + cmpz[wz]);
            if (wy > y) fyz.upd(wy, z, cmpy[wy] + cmpz[z]);
            fy.upd(y, z);
            fz.upd(z, y);
        }
    }
    cout << ans << '\n';
    return 0;
}

Compilation message

team.cpp: In member function 'int Fenwick::qry(int)':
team.cpp:25:24: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   25 |             i = (i & i + 1) - 1;
      |                      ~~^~~
team.cpp: In member function 'void Fenwick2D::upd(int, int, int)':
team.cpp:54:48: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   54 |             for (int j = J; j >= 0; j = (j & j + 1) - 1) {
      |                                              ~~^~~
team.cpp:57:24: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   57 |             i = (i & i + 1) - 1;
      |                      ~~^~~
team.cpp: In function 'int main()':
team.cpp:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for (int x = 0; x < cmpx.size(); x++) {
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 600 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 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 600 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 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 33 ms 7260 KB Output is correct
27 Correct 28 ms 4932 KB Output is correct
28 Correct 20 ms 4444 KB Output is correct
29 Correct 14 ms 3208 KB Output is correct
30 Correct 11 ms 2908 KB Output is correct
31 Correct 19 ms 3164 KB Output is correct
32 Correct 7 ms 1116 KB Output is correct
33 Correct 2 ms 600 KB Output is correct
34 Correct 10 ms 2908 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
37 Correct 6 ms 1336 KB Output is correct
38 Correct 6 ms 1624 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 49 ms 5564 KB Output is correct
12 Correct 30 ms 4040 KB Output is correct
13 Correct 32 ms 4808 KB Output is correct
14 Correct 44 ms 6328 KB Output is correct
15 Correct 35 ms 5820 KB Output is correct
16 Correct 27 ms 5956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 49 ms 5564 KB Output is correct
12 Correct 30 ms 4040 KB Output is correct
13 Correct 32 ms 4808 KB Output is correct
14 Correct 44 ms 6328 KB Output is correct
15 Correct 35 ms 5820 KB Output is correct
16 Correct 27 ms 5956 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 92 ms 5224 KB Output is correct
23 Correct 85 ms 5044 KB Output is correct
24 Correct 60 ms 4036 KB Output is correct
25 Correct 79 ms 5500 KB Output is correct
26 Correct 38 ms 5816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 49 ms 5564 KB Output is correct
12 Correct 30 ms 4040 KB Output is correct
13 Correct 32 ms 4808 KB Output is correct
14 Correct 44 ms 6328 KB Output is correct
15 Correct 35 ms 5820 KB Output is correct
16 Correct 27 ms 5956 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 92 ms 5224 KB Output is correct
23 Correct 85 ms 5044 KB Output is correct
24 Correct 60 ms 4036 KB Output is correct
25 Correct 79 ms 5500 KB Output is correct
26 Correct 38 ms 5816 KB Output is correct
27 Correct 1 ms 600 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 6 ms 1116 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 275 ms 8972 KB Output is correct
35 Correct 253 ms 8632 KB Output is correct
36 Correct 233 ms 8672 KB Output is correct
37 Correct 190 ms 7928 KB Output is correct
38 Correct 71 ms 5568 KB Output is correct
39 Correct 94 ms 7240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 49 ms 5564 KB Output is correct
12 Correct 30 ms 4040 KB Output is correct
13 Correct 32 ms 4808 KB Output is correct
14 Correct 44 ms 6328 KB Output is correct
15 Correct 35 ms 5820 KB Output is correct
16 Correct 27 ms 5956 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 92 ms 5224 KB Output is correct
23 Correct 85 ms 5044 KB Output is correct
24 Correct 60 ms 4036 KB Output is correct
25 Correct 79 ms 5500 KB Output is correct
26 Correct 38 ms 5816 KB Output is correct
27 Correct 1 ms 600 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 6 ms 1116 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 275 ms 8972 KB Output is correct
35 Correct 253 ms 8632 KB Output is correct
36 Correct 233 ms 8672 KB Output is correct
37 Correct 190 ms 7928 KB Output is correct
38 Correct 71 ms 5568 KB Output is correct
39 Correct 94 ms 7240 KB Output is correct
40 Correct 12 ms 2908 KB Output is correct
41 Correct 19 ms 3096 KB Output is correct
42 Correct 6 ms 1368 KB Output is correct
43 Correct 6 ms 1308 KB Output is correct
44 Correct 1771 ms 68832 KB Output is correct
45 Correct 813 ms 59180 KB Output is correct
46 Correct 968 ms 63256 KB Output is correct
47 Correct 647 ms 58472 KB Output is correct
48 Correct 70 ms 5800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 600 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 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 33 ms 7260 KB Output is correct
27 Correct 28 ms 4932 KB Output is correct
28 Correct 20 ms 4444 KB Output is correct
29 Correct 14 ms 3208 KB Output is correct
30 Correct 11 ms 2908 KB Output is correct
31 Correct 19 ms 3164 KB Output is correct
32 Correct 7 ms 1116 KB Output is correct
33 Correct 2 ms 600 KB Output is correct
34 Correct 10 ms 2908 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
37 Correct 6 ms 1336 KB Output is correct
38 Correct 6 ms 1624 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 512 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 49 ms 5564 KB Output is correct
51 Correct 30 ms 4040 KB Output is correct
52 Correct 32 ms 4808 KB Output is correct
53 Correct 44 ms 6328 KB Output is correct
54 Correct 35 ms 5820 KB Output is correct
55 Correct 27 ms 5956 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 348 KB Output is correct
61 Correct 92 ms 5224 KB Output is correct
62 Correct 85 ms 5044 KB Output is correct
63 Correct 60 ms 4036 KB Output is correct
64 Correct 79 ms 5500 KB Output is correct
65 Correct 38 ms 5816 KB Output is correct
66 Correct 1 ms 600 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 6 ms 1116 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 275 ms 8972 KB Output is correct
74 Correct 253 ms 8632 KB Output is correct
75 Correct 233 ms 8672 KB Output is correct
76 Correct 190 ms 7928 KB Output is correct
77 Correct 71 ms 5568 KB Output is correct
78 Correct 94 ms 7240 KB Output is correct
79 Correct 12 ms 2908 KB Output is correct
80 Correct 19 ms 3096 KB Output is correct
81 Correct 6 ms 1368 KB Output is correct
82 Correct 6 ms 1308 KB Output is correct
83 Correct 1771 ms 68832 KB Output is correct
84 Correct 813 ms 59180 KB Output is correct
85 Correct 968 ms 63256 KB Output is correct
86 Correct 647 ms 58472 KB Output is correct
87 Correct 70 ms 5800 KB Output is correct
88 Execution timed out 2088 ms 210984 KB Time limit exceeded
89 Halted 0 ms 0 KB -