이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
map<int, vector<array<int, 2>>> mp;
for (int i = 0; i < n; i++) {
int x, y, z;
cin >> x >> y >> z;
mp[z].push_back({x, y});
}
set<array<int, 2>> xy;
set<array<int, 2>> yx;
set<array<int, 2>> xy_defer;
set<array<int, 2>> yx_defer;
static const int INF = 1e9;
auto add = [&](int x, int y) -> void {
bool popped = false;
while (!xy_defer.empty()) {
auto it = xy_defer.lower_bound(array<int, 2>{x, -INF});
if (it == xy_defer.begin()) break;
it--;
auto [xx, yy] = *it;
if (yy <= y) break;
xy_defer.erase(it);
yx_defer.erase({yy, xx});
xy.insert({xx, yy});
yx.insert({yy, xx});
popped = true;
}
while (!yx_defer.empty()) {
auto it = yx_defer.lower_bound(array<int, 2>{y, -INF});
if (it == yx_defer.begin()) break;
it--;
auto [yy, xx] = *it;
if (xx <= x) break;
yx_defer.erase(it);
xy_defer.erase({xx, yy});
xy.insert({xx, yy});
yx.insert({yy, xx});
popped = true;
}
if (popped) {
xy.insert({x, y});
yx.insert({y, x});
} else {
xy_defer.insert({x, y});
yx_defer.insert({y, x});
}
};
auto query = [&](int x, int y) -> int {
if (xy.empty()) return -INF;
int xx = (*xy.rbegin())[0];
int yy = (*yx.rbegin())[0];
if (xx <= x || yy <= y) return -INF;
return xx + yy;
};
int res = -1;
for (auto [z, xy] : mp) {
for (auto [x, y] : xy) {
res = max(res, z + query(x, y));
}
for (auto [x, y] : xy) {
add(x, y);
}
}
cout << res << '\n';
}
# | 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... |