//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 150005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 1<<30;
struct segtree{
pii seg[4 * maxn];
int z[4 * maxn], minz[maxn];
int tag[4 * maxn];
void push(int cur, int l, int r) {
if (!tag[cur]) return;
z[cur] = tag[cur];
if (r - l > 1) {
tag[cur*2] = tag[cur];
tag[cur*2+1] = tag[cur];
}
tag[cur] = 0;
}
void pull(int cur, int l, int r) {
int mid = (l + r) / 2;
push(cur*2, l, mid), push(cur*2+1, mid, r);
seg[cur] = max(seg[cur*2], seg[cur*2+1]);
z[cur] = max(z[cur*2], z[cur*2+1]);
}
void init(int cur, int l, int r) {
if (r <= l) return;
if (r - l == 1) {
seg[cur] = {0, l};
minz[l] = inf;
return;
}
int m = (l + r) / 2;
init(cur*2, l, m), init(cur*2+1, m, r);
pull(cur, l, r);
}
void modify(int cur, int l, int r, int ql, int qr, int val) {
if (r <= l || ql >= r || qr <= l) return;
push(cur, l, r);
if (ql <= l && qr >= r) {
tag[cur] = val;
return;
}
int m = (l + r) / 2;
modify(cur*2, l, m, ql, qr, val);
modify(cur*2+1, m, r, ql, qr, val);
pull(cur, l, r);
}
void ch(int cur, int l, int r, int ind) {
if (r <= l) return;
push(cur, l, r);
if (r - l == 1) {
if (z[cur] > minz[l]) seg[cur].ff = z[cur];
return;
}
int m = (l + r) / 2;
if (ind < m) ch(cur*2, l, m, ind);
else ch(cur*2+1, m, r, ind);
pull(cur, l, r);
}
int search(int cur, int l, int r, int v) { //smallest index with z[x] >= v
if (r <= l) return 0;
push(cur, l, r);
if (r - l == 1) {
if (z[cur] < v) return l+1;
else return l;
}
int m = (l + r) / 2;
if (z[cur*2] >= v) return search(cur*2, l, m, v);
else return search(cur*2+1, m, r, v);
}
pii query(int cur, int l, int r, int ql, int qr) {
if (r <= l || ql >= r || qr <= l) return {-1, 0};
push(cur, l, r);
if (ql <= l && qr >= r) return seg[cur];
int m = (l + r) / 2;
return max(query(cur*2, l, m, ql, qr), query(cur*2+1, m, r, ql, qr));
}
} tr;
struct obj{
int x, y, z;
obj(){x = y = z = 0;}
obj(int a, int b, int c){x = a, y = b, z = c;}
} a[maxn];
vector<int> xv, yv;
vector<int> ev[maxn];
int main() {
io
int n;
cin >> n;
for (int i = 0;i < n;i++) {
cin >> a[i].x >> a[i].y >> a[i].z;
xv.push_back(a[i].x);
yv.push_back(a[i].y);
}
sort(xv.begin(), xv.end());
sort(yv.begin(), yv.end());
xv.resize(int(unique(xv.begin(), xv.end()) - xv.begin()));
yv.resize(int(unique(yv.begin(), yv.end()) - yv.begin()));
for (int i = 0;i < n;i++) {
a[i].x = lower_bound(xv.begin(), xv.end(), a[i].x) - xv.begin();
a[i].y = lower_bound(yv.begin(), yv.end(), a[i].y) - yv.begin();
ev[a[i].x].push_back(i);
}
int ans = -1;
int siz = yv.size();
tr.init(1, 0, siz);
for (int it = 0;it < n;it++) {
for (int i:ev[it]) {
pii best = tr.query(1, 0, siz, a[i].y+1, siz);
if (best.ff != -1 && best.ff > a[i].z) {
ans = max(ans, xv[a[i].x] + yv[best.ss] + best.ff);
}
}
for (int i:ev[it]) {
int z = a[i].z;
int rig = tr.search(1, 0, siz, z);
tr.modify(1, 0, siz, a[i].y + 1, rig, z);
tr.minz[a[i].y] = min(tr.minz[a[i].y], z);
tr.ch(1, 0, siz, a[i].y);
tr.ch(1, 0, siz, rig-1);
}
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10196 KB |
Output is correct |
2 |
Correct |
6 ms |
10324 KB |
Output is correct |
3 |
Correct |
7 ms |
10216 KB |
Output is correct |
4 |
Correct |
6 ms |
10320 KB |
Output is correct |
5 |
Correct |
5 ms |
10236 KB |
Output is correct |
6 |
Correct |
5 ms |
10272 KB |
Output is correct |
7 |
Correct |
4 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
10196 KB |
Output is correct |
9 |
Correct |
4 ms |
10196 KB |
Output is correct |
10 |
Correct |
5 ms |
10196 KB |
Output is correct |
11 |
Correct |
6 ms |
10212 KB |
Output is correct |
12 |
Correct |
4 ms |
10196 KB |
Output is correct |
13 |
Correct |
5 ms |
10196 KB |
Output is correct |
14 |
Correct |
6 ms |
10324 KB |
Output is correct |
15 |
Correct |
6 ms |
10292 KB |
Output is correct |
16 |
Correct |
7 ms |
10420 KB |
Output is correct |
17 |
Correct |
7 ms |
10324 KB |
Output is correct |
18 |
Correct |
6 ms |
10308 KB |
Output is correct |
19 |
Correct |
5 ms |
10304 KB |
Output is correct |
20 |
Correct |
5 ms |
10324 KB |
Output is correct |
21 |
Correct |
5 ms |
10308 KB |
Output is correct |
22 |
Correct |
5 ms |
10308 KB |
Output is correct |
23 |
Correct |
6 ms |
10304 KB |
Output is correct |
24 |
Correct |
5 ms |
10324 KB |
Output is correct |
25 |
Correct |
6 ms |
10324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10196 KB |
Output is correct |
2 |
Correct |
6 ms |
10324 KB |
Output is correct |
3 |
Correct |
7 ms |
10216 KB |
Output is correct |
4 |
Correct |
6 ms |
10320 KB |
Output is correct |
5 |
Correct |
5 ms |
10236 KB |
Output is correct |
6 |
Correct |
5 ms |
10272 KB |
Output is correct |
7 |
Correct |
4 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
10196 KB |
Output is correct |
9 |
Correct |
4 ms |
10196 KB |
Output is correct |
10 |
Correct |
5 ms |
10196 KB |
Output is correct |
11 |
Correct |
6 ms |
10212 KB |
Output is correct |
12 |
Correct |
4 ms |
10196 KB |
Output is correct |
13 |
Correct |
5 ms |
10196 KB |
Output is correct |
14 |
Correct |
6 ms |
10324 KB |
Output is correct |
15 |
Correct |
6 ms |
10292 KB |
Output is correct |
16 |
Correct |
7 ms |
10420 KB |
Output is correct |
17 |
Correct |
7 ms |
10324 KB |
Output is correct |
18 |
Correct |
6 ms |
10308 KB |
Output is correct |
19 |
Correct |
5 ms |
10304 KB |
Output is correct |
20 |
Correct |
5 ms |
10324 KB |
Output is correct |
21 |
Correct |
5 ms |
10308 KB |
Output is correct |
22 |
Correct |
5 ms |
10308 KB |
Output is correct |
23 |
Correct |
6 ms |
10304 KB |
Output is correct |
24 |
Correct |
5 ms |
10324 KB |
Output is correct |
25 |
Correct |
6 ms |
10324 KB |
Output is correct |
26 |
Correct |
10 ms |
10580 KB |
Output is correct |
27 |
Incorrect |
9 ms |
10444 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10196 KB |
Output is correct |
2 |
Correct |
6 ms |
10196 KB |
Output is correct |
3 |
Correct |
7 ms |
10196 KB |
Output is correct |
4 |
Correct |
5 ms |
10196 KB |
Output is correct |
5 |
Correct |
7 ms |
10272 KB |
Output is correct |
6 |
Correct |
5 ms |
10196 KB |
Output is correct |
7 |
Correct |
5 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
10196 KB |
Output is correct |
9 |
Correct |
5 ms |
10196 KB |
Output is correct |
10 |
Correct |
5 ms |
10196 KB |
Output is correct |
11 |
Correct |
48 ms |
12288 KB |
Output is correct |
12 |
Correct |
38 ms |
11860 KB |
Output is correct |
13 |
Correct |
48 ms |
12740 KB |
Output is correct |
14 |
Correct |
59 ms |
13424 KB |
Output is correct |
15 |
Correct |
49 ms |
12976 KB |
Output is correct |
16 |
Correct |
37 ms |
13536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10196 KB |
Output is correct |
2 |
Correct |
6 ms |
10196 KB |
Output is correct |
3 |
Correct |
7 ms |
10196 KB |
Output is correct |
4 |
Correct |
5 ms |
10196 KB |
Output is correct |
5 |
Correct |
7 ms |
10272 KB |
Output is correct |
6 |
Correct |
5 ms |
10196 KB |
Output is correct |
7 |
Correct |
5 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
10196 KB |
Output is correct |
9 |
Correct |
5 ms |
10196 KB |
Output is correct |
10 |
Correct |
5 ms |
10196 KB |
Output is correct |
11 |
Correct |
48 ms |
12288 KB |
Output is correct |
12 |
Correct |
38 ms |
11860 KB |
Output is correct |
13 |
Correct |
48 ms |
12740 KB |
Output is correct |
14 |
Correct |
59 ms |
13424 KB |
Output is correct |
15 |
Correct |
49 ms |
12976 KB |
Output is correct |
16 |
Correct |
37 ms |
13536 KB |
Output is correct |
17 |
Correct |
4 ms |
10196 KB |
Output is correct |
18 |
Correct |
5 ms |
10324 KB |
Output is correct |
19 |
Correct |
5 ms |
10196 KB |
Output is correct |
20 |
Correct |
6 ms |
10308 KB |
Output is correct |
21 |
Correct |
6 ms |
10324 KB |
Output is correct |
22 |
Correct |
81 ms |
12984 KB |
Output is correct |
23 |
Correct |
67 ms |
13016 KB |
Output is correct |
24 |
Correct |
51 ms |
12368 KB |
Output is correct |
25 |
Correct |
65 ms |
13476 KB |
Output is correct |
26 |
Correct |
52 ms |
13420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10196 KB |
Output is correct |
2 |
Correct |
6 ms |
10196 KB |
Output is correct |
3 |
Correct |
7 ms |
10196 KB |
Output is correct |
4 |
Correct |
5 ms |
10196 KB |
Output is correct |
5 |
Correct |
7 ms |
10272 KB |
Output is correct |
6 |
Correct |
5 ms |
10196 KB |
Output is correct |
7 |
Correct |
5 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
10196 KB |
Output is correct |
9 |
Correct |
5 ms |
10196 KB |
Output is correct |
10 |
Correct |
5 ms |
10196 KB |
Output is correct |
11 |
Correct |
48 ms |
12288 KB |
Output is correct |
12 |
Correct |
38 ms |
11860 KB |
Output is correct |
13 |
Correct |
48 ms |
12740 KB |
Output is correct |
14 |
Correct |
59 ms |
13424 KB |
Output is correct |
15 |
Correct |
49 ms |
12976 KB |
Output is correct |
16 |
Correct |
37 ms |
13536 KB |
Output is correct |
17 |
Correct |
4 ms |
10196 KB |
Output is correct |
18 |
Correct |
5 ms |
10324 KB |
Output is correct |
19 |
Correct |
5 ms |
10196 KB |
Output is correct |
20 |
Correct |
6 ms |
10308 KB |
Output is correct |
21 |
Correct |
6 ms |
10324 KB |
Output is correct |
22 |
Correct |
81 ms |
12984 KB |
Output is correct |
23 |
Correct |
67 ms |
13016 KB |
Output is correct |
24 |
Correct |
51 ms |
12368 KB |
Output is correct |
25 |
Correct |
65 ms |
13476 KB |
Output is correct |
26 |
Correct |
52 ms |
13420 KB |
Output is correct |
27 |
Correct |
7 ms |
10324 KB |
Output is correct |
28 |
Correct |
5 ms |
10324 KB |
Output is correct |
29 |
Correct |
5 ms |
10240 KB |
Output is correct |
30 |
Correct |
5 ms |
10304 KB |
Output is correct |
31 |
Correct |
9 ms |
10312 KB |
Output is correct |
32 |
Correct |
8 ms |
10328 KB |
Output is correct |
33 |
Correct |
7 ms |
10312 KB |
Output is correct |
34 |
Correct |
123 ms |
13460 KB |
Output is correct |
35 |
Correct |
104 ms |
13308 KB |
Output is correct |
36 |
Correct |
115 ms |
13568 KB |
Output is correct |
37 |
Correct |
105 ms |
13964 KB |
Output is correct |
38 |
Correct |
79 ms |
13620 KB |
Output is correct |
39 |
Correct |
47 ms |
12488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10196 KB |
Output is correct |
2 |
Correct |
6 ms |
10196 KB |
Output is correct |
3 |
Correct |
7 ms |
10196 KB |
Output is correct |
4 |
Correct |
5 ms |
10196 KB |
Output is correct |
5 |
Correct |
7 ms |
10272 KB |
Output is correct |
6 |
Correct |
5 ms |
10196 KB |
Output is correct |
7 |
Correct |
5 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
10196 KB |
Output is correct |
9 |
Correct |
5 ms |
10196 KB |
Output is correct |
10 |
Correct |
5 ms |
10196 KB |
Output is correct |
11 |
Correct |
48 ms |
12288 KB |
Output is correct |
12 |
Correct |
38 ms |
11860 KB |
Output is correct |
13 |
Correct |
48 ms |
12740 KB |
Output is correct |
14 |
Correct |
59 ms |
13424 KB |
Output is correct |
15 |
Correct |
49 ms |
12976 KB |
Output is correct |
16 |
Correct |
37 ms |
13536 KB |
Output is correct |
17 |
Correct |
4 ms |
10196 KB |
Output is correct |
18 |
Correct |
5 ms |
10324 KB |
Output is correct |
19 |
Correct |
5 ms |
10196 KB |
Output is correct |
20 |
Correct |
6 ms |
10308 KB |
Output is correct |
21 |
Correct |
6 ms |
10324 KB |
Output is correct |
22 |
Correct |
81 ms |
12984 KB |
Output is correct |
23 |
Correct |
67 ms |
13016 KB |
Output is correct |
24 |
Correct |
51 ms |
12368 KB |
Output is correct |
25 |
Correct |
65 ms |
13476 KB |
Output is correct |
26 |
Correct |
52 ms |
13420 KB |
Output is correct |
27 |
Correct |
7 ms |
10324 KB |
Output is correct |
28 |
Correct |
5 ms |
10324 KB |
Output is correct |
29 |
Correct |
5 ms |
10240 KB |
Output is correct |
30 |
Correct |
5 ms |
10304 KB |
Output is correct |
31 |
Correct |
9 ms |
10312 KB |
Output is correct |
32 |
Correct |
8 ms |
10328 KB |
Output is correct |
33 |
Correct |
7 ms |
10312 KB |
Output is correct |
34 |
Correct |
123 ms |
13460 KB |
Output is correct |
35 |
Correct |
104 ms |
13308 KB |
Output is correct |
36 |
Correct |
115 ms |
13568 KB |
Output is correct |
37 |
Correct |
105 ms |
13964 KB |
Output is correct |
38 |
Correct |
79 ms |
13620 KB |
Output is correct |
39 |
Correct |
47 ms |
12488 KB |
Output is correct |
40 |
Incorrect |
9 ms |
10452 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10196 KB |
Output is correct |
2 |
Correct |
6 ms |
10324 KB |
Output is correct |
3 |
Correct |
7 ms |
10216 KB |
Output is correct |
4 |
Correct |
6 ms |
10320 KB |
Output is correct |
5 |
Correct |
5 ms |
10236 KB |
Output is correct |
6 |
Correct |
5 ms |
10272 KB |
Output is correct |
7 |
Correct |
4 ms |
10196 KB |
Output is correct |
8 |
Correct |
5 ms |
10196 KB |
Output is correct |
9 |
Correct |
4 ms |
10196 KB |
Output is correct |
10 |
Correct |
5 ms |
10196 KB |
Output is correct |
11 |
Correct |
6 ms |
10212 KB |
Output is correct |
12 |
Correct |
4 ms |
10196 KB |
Output is correct |
13 |
Correct |
5 ms |
10196 KB |
Output is correct |
14 |
Correct |
6 ms |
10324 KB |
Output is correct |
15 |
Correct |
6 ms |
10292 KB |
Output is correct |
16 |
Correct |
7 ms |
10420 KB |
Output is correct |
17 |
Correct |
7 ms |
10324 KB |
Output is correct |
18 |
Correct |
6 ms |
10308 KB |
Output is correct |
19 |
Correct |
5 ms |
10304 KB |
Output is correct |
20 |
Correct |
5 ms |
10324 KB |
Output is correct |
21 |
Correct |
5 ms |
10308 KB |
Output is correct |
22 |
Correct |
5 ms |
10308 KB |
Output is correct |
23 |
Correct |
6 ms |
10304 KB |
Output is correct |
24 |
Correct |
5 ms |
10324 KB |
Output is correct |
25 |
Correct |
6 ms |
10324 KB |
Output is correct |
26 |
Correct |
10 ms |
10580 KB |
Output is correct |
27 |
Incorrect |
9 ms |
10444 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |