답안 #884699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884699 2023-12-08T06:22:49 Z Desh03 Team Contest (JOI22_team) C++17
0 / 100
46 ms 6332 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 Fenwick2D {
    vector<unordered_map<int, int>> 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++) {
        sort(X[x].begin(), X[x].end());
        for (auto &[y, z] : X[x]) {
            int wyz = fyz.qry(y + 1, z + 1), wz = fy.qry(y - 1), wy = fz.qry(z - 1);
            if (wyz) chmax(ans, cmpx[x] + wyz);
            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:39:48: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   39 |             for (int j = J; j >= 0; j = (j & j + 1) - 1) {
      |                                              ~~^~~
team.cpp:42:24: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   42 |             i = (i & i + 1) - 1;
      |                      ~~^~~
team.cpp: In function 'int main()':
team.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int x = 0; x < cmpx.size(); x++) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
8 Correct 1 ms 784 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 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
8 Correct 1 ms 784 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 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 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 46 ms 6332 KB Output is correct
12 Incorrect 29 ms 4816 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 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 46 ms 6332 KB Output is correct
12 Incorrect 29 ms 4816 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 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 46 ms 6332 KB Output is correct
12 Incorrect 29 ms 4816 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 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 46 ms 6332 KB Output is correct
12 Incorrect 29 ms 4816 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
8 Correct 1 ms 784 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 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -