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;
#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)
template <class T>
bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#ifndef DEBUG
#define cerr if(0) cerr
#endif
const int MAXN = 150005;
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
int n;
iii xyz[MAXN];
set<ii> st[2];
ii lft, rht;
int ans;
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> n;
REP (i, 0, n) {
int x, y, z; cin >> x >> y >> z;
xyz[i] = {x, y, z};
}
sort(xyz, xyz + n, [&] (iii l, iii r) {
return get<1>(l) < get<1>(r);
});
ans = -1;
int ptr = 0;
int mx[2] = {-1, -1}, mz[2] = {-1, -1};
REP (i, 0, n) {
while (ptr < i && get<1>(xyz[ptr]) < get<1>(xyz[i])) {
auto [x, y, z] = xyz[ptr++];
cerr << x << ' ' << z << '\n';
{
cerr << ' ' << 0 << ' ' << mx[0] << ' ' << mz[0] << '\n';
auto [ptr, yes] = st[0].insert({x, z});
for (auto [a, b] : st[0]) {
cerr << " " << a << ' ' << b << '\n';
}
while (next(ptr) != st[0].end() && next(ptr) -> SE < z) {
bool bz = mz[0] <= z;
bool bx = mx[0] <= next(ptr) -> FI;
if (bx && bz) {
mz[0] = z;
mx[0] = next(ptr) -> FI;
}
st[0].erase(next(ptr));
}
if (ptr != st[0].begin() && prev(ptr) -> SE > z) {
bool bz = mz[0] <= prev(ptr) -> SE;
bool bx = mx[0] <= x;
cerr << " " << x << ' ' << (prev(ptr) -> SE) << '\n';
if (bx && bz) {
mz[0] = prev(ptr) -> SE;
mx[0] = x;
}
st[0].erase(ptr);
}
}
{
cerr << ' ' << 1 << ' ' << mx[1] << ' ' << mz[1] << '\n';
auto [ptr, yes] = st[1].insert({x, z});
while (ptr != st[1].begin() && prev(ptr) -> SE > z) {
bool bz = mz[1] <= prev(ptr) -> SE;
bool bx = mx[1] <= x;
if (bx && bz) {
mz[1] = prev(ptr) -> SE;
mx[1] = x;
}
st[1].erase(prev(ptr));
}
if (next(ptr) != st[1].end() && next(ptr) -> SE < z) {
bool bz = mz[1] <= z;
bool bx = mx[1] <= next(ptr) -> FI;
if (bx && bz) {
mz[1] = z;
mx[1] = next(ptr) -> FI;
}
st[1].erase(ptr);
}
}
}
REP (z, 0, 2) {
int my = -INF;
auto [cx, cy, cz] = xyz[i];
if (mx[z] == -1) continue;
if (cx < mx[z] && cz < mz[z]) {
my = cy;
}
if (my != -INF) {
mxto(ans, mx[z] + my + mz[z]);
}
}
}
cout << ans << '\n';
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... |