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 f first
#define s second
#define int long long
const int N = 2e5 + 69;
const int A = 4010;
const int inf = 1e9;
vector<vector<int>> st(A, vector<int>(4 * A, inf));
int n, a[N], b[N], c[N], d[A][A], mn[A][A];
int gmx[A][A], gmn[A][A];
void Modify(int v, int tl, int tr, int r, int p, int x) {
if (tl == tr)
st[r][v] = min(st[r][v], x);
else {
int mid = (tl + tr) / 2;
if (p <= mid)
Modify(v * 2, tl, mid, r, p, x);
else
Modify(v * 2 + 1, mid + 1, tr, r, p, x);
st[r][v] = min(st[r][v * 2], st[r][v * 2 + 1]);
}
}
int Get(int v, int tl, int tr, int L, int R, int r, int x) {
if (tl > R || tr < L)
return inf;
else if (tl == tr)
return tl;
else {
int mid = (tl + tr) / 2;
if (st[r][v * 2 + 1] < x)
return Get(v * 2 + 1, mid + 1, tr, L, R, r, x);
else
return Get(v * 2, tl, mid, L, R, r, x);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i] >> b[i] >> c[i];
for (int i = 0;i < A;i++) {
for (int j = 0;j < A;j++) {
gmn[i][j] = inf;
gmx[i][j] = -inf;
d[i][j] = -inf;
mn[i][j] = inf;
}
}
for (int i = 1;i <= n;i++) {
gmx[a[i]][b[i]] = max(c[i], gmx[a[i]][b[i]]);
gmn[a[i]][b[i]] = min(c[i], gmn[a[i]][b[i]]);
Modify(1, 1, A, a[i], b[i], c[i]);
}
for (int i = 1;i < A;i++) {
for (int j = 1;j < A;j++)
d[i][j] = max({d[i][j - 1], d[i - 1][j], gmx[i][j]});
}
int ans = -1;
for (int i = 1;i <= n;i++) {
for (int j = a[i] - 1;j >= 1;j--) {
int y = Get(1, 1, A, b[i] + 1, A, j, d[j][b[i]]);
if (y != inf && gmn[j][y] < d[j][b[i]]) {
ans = max(ans, a[i] + y + d[j][b[i]]);
}
}
}
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... |