#include <bits/stdc++.h>
bool home = 1;
using namespace std;
struct T {
int x;
int y;
int z;
int tx;
int ty;
int tz;
};
bool cmp_x_inv(T a,T b) {
return a.x>b.x;
}
typedef long long ll;
const int N=150000+7;
const int INF=(int)1e9+7;
int n,zm[N],invy[N],invz[N],value[N];
T a[N];
int aib1[N];
void clr1() {
for (int i=1;i<=n;i++) aib1[i]=-INF;
}
int get1(int i) {
int sol=-INF;
while (i) {
sol=max(sol,aib1[i]);
i-=i&(-i);
}
return sol;
}
void upd1(int i,int x) {
while (i<=n){
aib1[i]=max(aib1[i],x);
i+=i&(-i);
}
}
unordered_map<int, int> aib[N];
int dim[N];
void clr() {
for (int i=1;i<=n;i++) aib[i].clear(),dim[i]=0;
}
void upd(int x,int y,int val) {
for (int i=x;i<=n;i+=i&(-i)) {
for (int j=y;j<=n;j+=j&(-j)) {
aib[i][j]=max(aib[i][j],val);
}
}
}
int get(int x,int y) {
int sol=-INF;
for (int i=x;i>=1;i-=i&(-i)) {
for (int j=y;j>=1;j-=j&(-j)) {
if (aib[i].count(j)) {
sol=max(sol,aib[i][j]);
}
}
}
return sol;
}
signed main() {
#ifdef ONLINE_JUDGE
home = 0;
#endif
home=0;
if (home) {
freopen("I_am_iron_man", "r", stdin);
}
else {
ios::sync_with_stdio(0); cin.tie(0);
}
cin>>n;
for (int i=1;i<=n;i++) {
cin>>a[i].x>>a[i].y>>a[i].z;
}
sort(a+1,a+n+1,cmp_x_inv);
{
map<int, int> tx,ty,tz;
for (int i=1;i<=n;i++) tx[a[i].x]=0,ty[a[i].y]=0,tz[a[i].z]=0;
int ind;
ind=0; for (auto &it:tx)it.second=++ind;
ind=0; for (auto &it:ty)it.second=++ind, invy[ind]=it.first;
ind=0; for (auto &it:tz)it.second=++ind, invz[ind]=it.first;
for (int i=1;i<=n;i++) a[i].tx=tx[a[i].x], a[i].ty=ty[a[i].y], a[i].tz=tz[a[i].z];
}
int print=-1;
for (int ITER=0;ITER<2;ITER++) {
clr1();
clr();
for (int i=n;i>=1;i--) { /// optimize using aib
zm[i]=get1(a[i].ty-1);
upd1(a[i].ty,a[i].tz);
if (zm[i]<=a[i].tz) zm[i]=-INF;
if (1<=zm[i]&&zm[i]<=n) value[i]=invz[zm[i]]+a[i].y; else assert(zm[i]==-INF);
}
for (int i=1;i<=n;i++) {
if(zm[i]==-INF) continue;
int y=n+1-a[i].ty,z=n+1-zm[i];
for (int p=y;p<=n;p+=p&(-p)) {
dim[p]++;
}
}
for (int i=1;i<=n;i++) aib[i].rehash(5*dim[i]);
int last=n;
while(last>=1){
int first=last;
while(first-1>=1&&a[first-1].x==a[first].x) first--;
for (int i=first;i<=last;i++) {
print=max(print,get(n-a[i].ty,n-a[i].tz)+a[i].x);
}
for (int i=first;i<=last;i++) {
if (zm[i]!=-INF) {
upd(n+1-a[i].ty,n+1-zm[i],value[i]);
}
}
last=first-1;
}
for (int i=1;i<=n;i++) swap(a[i].y,a[i].z), swap(a[i].ty,a[i].tz), swap(invz[i],invy[i]);
}
cout<<print<<"\n";
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:118:25: warning: unused variable 'z' [-Wunused-variable]
118 | int y=n+1-a[i].ty,z=n+1-zm[i];
| ^
team.cpp:82:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen("I_am_iron_man", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8532 KB |
Output is correct |
2 |
Correct |
5 ms |
8456 KB |
Output is correct |
3 |
Correct |
5 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
8532 KB |
Output is correct |
5 |
Correct |
5 ms |
8532 KB |
Output is correct |
6 |
Correct |
5 ms |
8568 KB |
Output is correct |
7 |
Correct |
5 ms |
8572 KB |
Output is correct |
8 |
Correct |
7 ms |
8532 KB |
Output is correct |
9 |
Correct |
5 ms |
8532 KB |
Output is correct |
10 |
Correct |
5 ms |
8532 KB |
Output is correct |
11 |
Correct |
4 ms |
8532 KB |
Output is correct |
12 |
Correct |
4 ms |
8532 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
7 ms |
8648 KB |
Output is correct |
15 |
Correct |
5 ms |
8588 KB |
Output is correct |
16 |
Correct |
6 ms |
8616 KB |
Output is correct |
17 |
Correct |
6 ms |
8532 KB |
Output is correct |
18 |
Correct |
6 ms |
8560 KB |
Output is correct |
19 |
Correct |
6 ms |
8648 KB |
Output is correct |
20 |
Correct |
5 ms |
8532 KB |
Output is correct |
21 |
Correct |
6 ms |
8532 KB |
Output is correct |
22 |
Correct |
5 ms |
8532 KB |
Output is correct |
23 |
Correct |
5 ms |
8532 KB |
Output is correct |
24 |
Correct |
5 ms |
8532 KB |
Output is correct |
25 |
Correct |
5 ms |
8532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8532 KB |
Output is correct |
2 |
Correct |
5 ms |
8456 KB |
Output is correct |
3 |
Correct |
5 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
8532 KB |
Output is correct |
5 |
Correct |
5 ms |
8532 KB |
Output is correct |
6 |
Correct |
5 ms |
8568 KB |
Output is correct |
7 |
Correct |
5 ms |
8572 KB |
Output is correct |
8 |
Correct |
7 ms |
8532 KB |
Output is correct |
9 |
Correct |
5 ms |
8532 KB |
Output is correct |
10 |
Correct |
5 ms |
8532 KB |
Output is correct |
11 |
Correct |
4 ms |
8532 KB |
Output is correct |
12 |
Correct |
4 ms |
8532 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
7 ms |
8648 KB |
Output is correct |
15 |
Correct |
5 ms |
8588 KB |
Output is correct |
16 |
Correct |
6 ms |
8616 KB |
Output is correct |
17 |
Correct |
6 ms |
8532 KB |
Output is correct |
18 |
Correct |
6 ms |
8560 KB |
Output is correct |
19 |
Correct |
6 ms |
8648 KB |
Output is correct |
20 |
Correct |
5 ms |
8532 KB |
Output is correct |
21 |
Correct |
6 ms |
8532 KB |
Output is correct |
22 |
Correct |
5 ms |
8532 KB |
Output is correct |
23 |
Correct |
5 ms |
8532 KB |
Output is correct |
24 |
Correct |
5 ms |
8532 KB |
Output is correct |
25 |
Correct |
5 ms |
8532 KB |
Output is correct |
26 |
Correct |
36 ms |
11696 KB |
Output is correct |
27 |
Correct |
22 ms |
10200 KB |
Output is correct |
28 |
Correct |
21 ms |
10068 KB |
Output is correct |
29 |
Correct |
18 ms |
9488 KB |
Output is correct |
30 |
Correct |
14 ms |
9428 KB |
Output is correct |
31 |
Correct |
21 ms |
9868 KB |
Output is correct |
32 |
Correct |
13 ms |
9288 KB |
Output is correct |
33 |
Correct |
13 ms |
9172 KB |
Output is correct |
34 |
Correct |
12 ms |
9336 KB |
Output is correct |
35 |
Correct |
6 ms |
8692 KB |
Output is correct |
36 |
Correct |
6 ms |
8692 KB |
Output is correct |
37 |
Correct |
11 ms |
8860 KB |
Output is correct |
38 |
Correct |
12 ms |
8916 KB |
Output is correct |
39 |
Correct |
10 ms |
8916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8532 KB |
Output is correct |
2 |
Correct |
5 ms |
8532 KB |
Output is correct |
3 |
Correct |
5 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
8532 KB |
Output is correct |
5 |
Correct |
5 ms |
8532 KB |
Output is correct |
6 |
Correct |
5 ms |
8532 KB |
Output is correct |
7 |
Correct |
5 ms |
8532 KB |
Output is correct |
8 |
Correct |
4 ms |
8532 KB |
Output is correct |
9 |
Correct |
5 ms |
8484 KB |
Output is correct |
10 |
Correct |
5 ms |
8532 KB |
Output is correct |
11 |
Correct |
351 ms |
29024 KB |
Output is correct |
12 |
Correct |
189 ms |
19356 KB |
Output is correct |
13 |
Correct |
279 ms |
18712 KB |
Output is correct |
14 |
Correct |
319 ms |
25776 KB |
Output is correct |
15 |
Correct |
353 ms |
26284 KB |
Output is correct |
16 |
Correct |
374 ms |
19752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8532 KB |
Output is correct |
2 |
Correct |
5 ms |
8532 KB |
Output is correct |
3 |
Correct |
5 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
8532 KB |
Output is correct |
5 |
Correct |
5 ms |
8532 KB |
Output is correct |
6 |
Correct |
5 ms |
8532 KB |
Output is correct |
7 |
Correct |
5 ms |
8532 KB |
Output is correct |
8 |
Correct |
4 ms |
8532 KB |
Output is correct |
9 |
Correct |
5 ms |
8484 KB |
Output is correct |
10 |
Correct |
5 ms |
8532 KB |
Output is correct |
11 |
Correct |
351 ms |
29024 KB |
Output is correct |
12 |
Correct |
189 ms |
19356 KB |
Output is correct |
13 |
Correct |
279 ms |
18712 KB |
Output is correct |
14 |
Correct |
319 ms |
25776 KB |
Output is correct |
15 |
Correct |
353 ms |
26284 KB |
Output is correct |
16 |
Correct |
374 ms |
19752 KB |
Output is correct |
17 |
Correct |
5 ms |
8568 KB |
Output is correct |
18 |
Correct |
5 ms |
8532 KB |
Output is correct |
19 |
Correct |
5 ms |
8532 KB |
Output is correct |
20 |
Correct |
6 ms |
8532 KB |
Output is correct |
21 |
Correct |
9 ms |
8916 KB |
Output is correct |
22 |
Correct |
375 ms |
36612 KB |
Output is correct |
23 |
Correct |
385 ms |
30756 KB |
Output is correct |
24 |
Correct |
181 ms |
24424 KB |
Output is correct |
25 |
Correct |
252 ms |
29332 KB |
Output is correct |
26 |
Correct |
320 ms |
24524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8532 KB |
Output is correct |
2 |
Correct |
5 ms |
8532 KB |
Output is correct |
3 |
Correct |
5 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
8532 KB |
Output is correct |
5 |
Correct |
5 ms |
8532 KB |
Output is correct |
6 |
Correct |
5 ms |
8532 KB |
Output is correct |
7 |
Correct |
5 ms |
8532 KB |
Output is correct |
8 |
Correct |
4 ms |
8532 KB |
Output is correct |
9 |
Correct |
5 ms |
8484 KB |
Output is correct |
10 |
Correct |
5 ms |
8532 KB |
Output is correct |
11 |
Correct |
351 ms |
29024 KB |
Output is correct |
12 |
Correct |
189 ms |
19356 KB |
Output is correct |
13 |
Correct |
279 ms |
18712 KB |
Output is correct |
14 |
Correct |
319 ms |
25776 KB |
Output is correct |
15 |
Correct |
353 ms |
26284 KB |
Output is correct |
16 |
Correct |
374 ms |
19752 KB |
Output is correct |
17 |
Correct |
5 ms |
8568 KB |
Output is correct |
18 |
Correct |
5 ms |
8532 KB |
Output is correct |
19 |
Correct |
5 ms |
8532 KB |
Output is correct |
20 |
Correct |
6 ms |
8532 KB |
Output is correct |
21 |
Correct |
9 ms |
8916 KB |
Output is correct |
22 |
Correct |
375 ms |
36612 KB |
Output is correct |
23 |
Correct |
385 ms |
30756 KB |
Output is correct |
24 |
Correct |
181 ms |
24424 KB |
Output is correct |
25 |
Correct |
252 ms |
29332 KB |
Output is correct |
26 |
Correct |
320 ms |
24524 KB |
Output is correct |
27 |
Correct |
6 ms |
8660 KB |
Output is correct |
28 |
Correct |
5 ms |
8532 KB |
Output is correct |
29 |
Correct |
5 ms |
8532 KB |
Output is correct |
30 |
Correct |
5 ms |
8532 KB |
Output is correct |
31 |
Correct |
14 ms |
9400 KB |
Output is correct |
32 |
Correct |
6 ms |
8660 KB |
Output is correct |
33 |
Correct |
6 ms |
8660 KB |
Output is correct |
34 |
Correct |
480 ms |
48608 KB |
Output is correct |
35 |
Correct |
335 ms |
38688 KB |
Output is correct |
36 |
Correct |
379 ms |
39708 KB |
Output is correct |
37 |
Correct |
345 ms |
34248 KB |
Output is correct |
38 |
Correct |
320 ms |
30076 KB |
Output is correct |
39 |
Correct |
297 ms |
31668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8532 KB |
Output is correct |
2 |
Correct |
5 ms |
8532 KB |
Output is correct |
3 |
Correct |
5 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
8532 KB |
Output is correct |
5 |
Correct |
5 ms |
8532 KB |
Output is correct |
6 |
Correct |
5 ms |
8532 KB |
Output is correct |
7 |
Correct |
5 ms |
8532 KB |
Output is correct |
8 |
Correct |
4 ms |
8532 KB |
Output is correct |
9 |
Correct |
5 ms |
8484 KB |
Output is correct |
10 |
Correct |
5 ms |
8532 KB |
Output is correct |
11 |
Correct |
351 ms |
29024 KB |
Output is correct |
12 |
Correct |
189 ms |
19356 KB |
Output is correct |
13 |
Correct |
279 ms |
18712 KB |
Output is correct |
14 |
Correct |
319 ms |
25776 KB |
Output is correct |
15 |
Correct |
353 ms |
26284 KB |
Output is correct |
16 |
Correct |
374 ms |
19752 KB |
Output is correct |
17 |
Correct |
5 ms |
8568 KB |
Output is correct |
18 |
Correct |
5 ms |
8532 KB |
Output is correct |
19 |
Correct |
5 ms |
8532 KB |
Output is correct |
20 |
Correct |
6 ms |
8532 KB |
Output is correct |
21 |
Correct |
9 ms |
8916 KB |
Output is correct |
22 |
Correct |
375 ms |
36612 KB |
Output is correct |
23 |
Correct |
385 ms |
30756 KB |
Output is correct |
24 |
Correct |
181 ms |
24424 KB |
Output is correct |
25 |
Correct |
252 ms |
29332 KB |
Output is correct |
26 |
Correct |
320 ms |
24524 KB |
Output is correct |
27 |
Correct |
6 ms |
8660 KB |
Output is correct |
28 |
Correct |
5 ms |
8532 KB |
Output is correct |
29 |
Correct |
5 ms |
8532 KB |
Output is correct |
30 |
Correct |
5 ms |
8532 KB |
Output is correct |
31 |
Correct |
14 ms |
9400 KB |
Output is correct |
32 |
Correct |
6 ms |
8660 KB |
Output is correct |
33 |
Correct |
6 ms |
8660 KB |
Output is correct |
34 |
Correct |
480 ms |
48608 KB |
Output is correct |
35 |
Correct |
335 ms |
38688 KB |
Output is correct |
36 |
Correct |
379 ms |
39708 KB |
Output is correct |
37 |
Correct |
345 ms |
34248 KB |
Output is correct |
38 |
Correct |
320 ms |
30076 KB |
Output is correct |
39 |
Correct |
297 ms |
31668 KB |
Output is correct |
40 |
Correct |
13 ms |
9376 KB |
Output is correct |
41 |
Correct |
20 ms |
9836 KB |
Output is correct |
42 |
Correct |
10 ms |
8916 KB |
Output is correct |
43 |
Correct |
12 ms |
8908 KB |
Output is correct |
44 |
Correct |
985 ms |
58800 KB |
Output is correct |
45 |
Correct |
567 ms |
47788 KB |
Output is correct |
46 |
Correct |
624 ms |
49792 KB |
Output is correct |
47 |
Correct |
575 ms |
46660 KB |
Output is correct |
48 |
Correct |
363 ms |
28908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8532 KB |
Output is correct |
2 |
Correct |
5 ms |
8456 KB |
Output is correct |
3 |
Correct |
5 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
8532 KB |
Output is correct |
5 |
Correct |
5 ms |
8532 KB |
Output is correct |
6 |
Correct |
5 ms |
8568 KB |
Output is correct |
7 |
Correct |
5 ms |
8572 KB |
Output is correct |
8 |
Correct |
7 ms |
8532 KB |
Output is correct |
9 |
Correct |
5 ms |
8532 KB |
Output is correct |
10 |
Correct |
5 ms |
8532 KB |
Output is correct |
11 |
Correct |
4 ms |
8532 KB |
Output is correct |
12 |
Correct |
4 ms |
8532 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
7 ms |
8648 KB |
Output is correct |
15 |
Correct |
5 ms |
8588 KB |
Output is correct |
16 |
Correct |
6 ms |
8616 KB |
Output is correct |
17 |
Correct |
6 ms |
8532 KB |
Output is correct |
18 |
Correct |
6 ms |
8560 KB |
Output is correct |
19 |
Correct |
6 ms |
8648 KB |
Output is correct |
20 |
Correct |
5 ms |
8532 KB |
Output is correct |
21 |
Correct |
6 ms |
8532 KB |
Output is correct |
22 |
Correct |
5 ms |
8532 KB |
Output is correct |
23 |
Correct |
5 ms |
8532 KB |
Output is correct |
24 |
Correct |
5 ms |
8532 KB |
Output is correct |
25 |
Correct |
5 ms |
8532 KB |
Output is correct |
26 |
Correct |
36 ms |
11696 KB |
Output is correct |
27 |
Correct |
22 ms |
10200 KB |
Output is correct |
28 |
Correct |
21 ms |
10068 KB |
Output is correct |
29 |
Correct |
18 ms |
9488 KB |
Output is correct |
30 |
Correct |
14 ms |
9428 KB |
Output is correct |
31 |
Correct |
21 ms |
9868 KB |
Output is correct |
32 |
Correct |
13 ms |
9288 KB |
Output is correct |
33 |
Correct |
13 ms |
9172 KB |
Output is correct |
34 |
Correct |
12 ms |
9336 KB |
Output is correct |
35 |
Correct |
6 ms |
8692 KB |
Output is correct |
36 |
Correct |
6 ms |
8692 KB |
Output is correct |
37 |
Correct |
11 ms |
8860 KB |
Output is correct |
38 |
Correct |
12 ms |
8916 KB |
Output is correct |
39 |
Correct |
10 ms |
8916 KB |
Output is correct |
40 |
Correct |
5 ms |
8532 KB |
Output is correct |
41 |
Correct |
5 ms |
8532 KB |
Output is correct |
42 |
Correct |
5 ms |
8532 KB |
Output is correct |
43 |
Correct |
5 ms |
8532 KB |
Output is correct |
44 |
Correct |
5 ms |
8532 KB |
Output is correct |
45 |
Correct |
5 ms |
8532 KB |
Output is correct |
46 |
Correct |
5 ms |
8532 KB |
Output is correct |
47 |
Correct |
4 ms |
8532 KB |
Output is correct |
48 |
Correct |
5 ms |
8484 KB |
Output is correct |
49 |
Correct |
5 ms |
8532 KB |
Output is correct |
50 |
Correct |
351 ms |
29024 KB |
Output is correct |
51 |
Correct |
189 ms |
19356 KB |
Output is correct |
52 |
Correct |
279 ms |
18712 KB |
Output is correct |
53 |
Correct |
319 ms |
25776 KB |
Output is correct |
54 |
Correct |
353 ms |
26284 KB |
Output is correct |
55 |
Correct |
374 ms |
19752 KB |
Output is correct |
56 |
Correct |
5 ms |
8568 KB |
Output is correct |
57 |
Correct |
5 ms |
8532 KB |
Output is correct |
58 |
Correct |
5 ms |
8532 KB |
Output is correct |
59 |
Correct |
6 ms |
8532 KB |
Output is correct |
60 |
Correct |
9 ms |
8916 KB |
Output is correct |
61 |
Correct |
375 ms |
36612 KB |
Output is correct |
62 |
Correct |
385 ms |
30756 KB |
Output is correct |
63 |
Correct |
181 ms |
24424 KB |
Output is correct |
64 |
Correct |
252 ms |
29332 KB |
Output is correct |
65 |
Correct |
320 ms |
24524 KB |
Output is correct |
66 |
Correct |
6 ms |
8660 KB |
Output is correct |
67 |
Correct |
5 ms |
8532 KB |
Output is correct |
68 |
Correct |
5 ms |
8532 KB |
Output is correct |
69 |
Correct |
5 ms |
8532 KB |
Output is correct |
70 |
Correct |
14 ms |
9400 KB |
Output is correct |
71 |
Correct |
6 ms |
8660 KB |
Output is correct |
72 |
Correct |
6 ms |
8660 KB |
Output is correct |
73 |
Correct |
480 ms |
48608 KB |
Output is correct |
74 |
Correct |
335 ms |
38688 KB |
Output is correct |
75 |
Correct |
379 ms |
39708 KB |
Output is correct |
76 |
Correct |
345 ms |
34248 KB |
Output is correct |
77 |
Correct |
320 ms |
30076 KB |
Output is correct |
78 |
Correct |
297 ms |
31668 KB |
Output is correct |
79 |
Correct |
13 ms |
9376 KB |
Output is correct |
80 |
Correct |
20 ms |
9836 KB |
Output is correct |
81 |
Correct |
10 ms |
8916 KB |
Output is correct |
82 |
Correct |
12 ms |
8908 KB |
Output is correct |
83 |
Correct |
985 ms |
58800 KB |
Output is correct |
84 |
Correct |
567 ms |
47788 KB |
Output is correct |
85 |
Correct |
624 ms |
49792 KB |
Output is correct |
86 |
Correct |
575 ms |
46660 KB |
Output is correct |
87 |
Correct |
363 ms |
28908 KB |
Output is correct |
88 |
Execution timed out |
2083 ms |
166084 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |