Submission #884705

#TimeUsernameProblemLanguageResultExecution timeMemory
884705Desh03Team Contest (JOI22_team)C++17
64 / 100
2100 ms68696 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 Fenwick2D { vector<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++) { 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: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++) {
      |                     ~~^~~~~~~~~~~~~
#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...