This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 150005;
struct Fenwick {
int s[N];
void upd(int i, int x) {
for (; i < N; i += i & -i) {
s[i] = max(s[i], x);
}
}
int qry(int i) {
int res = 0;
for (; i; i -= i & -i) {
res = max(res, s[i]);
}
return res;
}
} ft[2];
int n;
int x[N], y[N], z[N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
array<vector<int>, 2> comp;
for (int i = 1; i <= n; ++i) {
cin >> x[i] >> y[i] >> z[i];
comp[0].push_back(y[i]);
comp[1].push_back(z[i]);
}
for (auto it : {0, 1}) {
sort(comp[it].begin(), comp[it].end());
comp[it].erase(unique(comp[it].begin(), comp[it].end()), comp[it].end());
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return x[i] < x[j];
});
auto ID = [&](const vector<int> &comp, int x) {
return lower_bound(comp.begin(), comp.end(), x) - comp.begin() + 1;
};
array<int, 2> cands{};
auto add = [&](int id) {
int Y = ID(comp[0], y[id]), Z = ID(comp[1], z[id]);
int rZ = ft[1].qry(Y - 1), lY = ft[0].qry(Z - 1);
if (rZ > z[id]) {
cands = max(cands, {y[id], rZ});
}
if (lY > y[id]) {
cands = max(cands, {lY, z[id]});
}
ft[0].upd(Z, y[id]);
ft[1].upd(Y, z[id]);
};
int res = -1;
for (int i = 0; i < n; ) {
int j = i;
while (j < n && x[ord[i]] == x[ord[j]]) {
if (cands[0] > y[ord[j]] && cands[1] > z[ord[j]]) {
res = max(res, x[ord[j]] + cands[0] + cands[1]);
}
++j;
}
while (i < j) {
add(ord[i++]);
}
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |