Submission #884702

#TimeUsernameProblemLanguageResultExecution timeMemory
884702Desh03Team Contest (JOI22_team)C++17
73 / 100
2088 ms210984 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...