#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define SZ(x) (int)(x.size())
#define ALL(x) x.begin(),x.end()
#define pb push_back
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S &&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 2005;
struct seg{
ll sum, lv, rv, v;
seg *lc=0, *rc=0;
};
int n;
void pull(seg *&o) {
if (!o->lc) {
if (o->v > 0)
o->sum = o->lv = o->rv = o->v;
else {
o->sum = o->v;
o->lv = o->rv = o->v = 0;
}
}else{
assert(o->lc && o->rc);
o->sum = o->lc->sum + o->rc->sum;
o->lv = max(o->lc->lv, o->lc->sum + o->rc->lv);
o->rv = max(o->rc->rv, o->rc->sum + o->lc->rv);
o->v = max({o->lc->v, o->rc->v, o->lc->rv + o->rc->lv});
assert(o->v >= 0);
}
}
void MO(int p, int v, seg *&o, int l=0, int r=n-1) {
if (l > p || r<p) return;
if (l == r) {
o->v = v;
pull(o);
return;
}
int mid = l+r>>1;
MO(p,v,o->lc,l,mid);
MO(p,v,o->rc,mid+1,r);
pull(o);
}
ll arr[maxn];
void build(seg * &o, int l=0, int r=n-1) {
if (l == r) {
o->v = arr[l]; pull(o); return;
}
int mid = l+r>>1;
o->lc = new seg();
build(o->lc, l, mid);
o->rc = new seg();
build(o->rc, mid+1, r);
pull(o);
}
struct pt{
int x, y;
ll v;
};
struct Ev{
double sl;
int a,b;
};
int at[maxn];
signed main(){
IOS();
cin>>n;
seg* root = new seg();
vector<pt> v(n);
for (int i = 0; i<n; ++i) {
cin>>v[i].x>>v[i].y>>v[i].v;
}
sort(v.begin(), v.end(), [&](pt a, pt b){return a.y!=b.y?a.y>b.y:a.x<b.x;});
for (int i = 0; i<n; ++i) {
arr[i] = v[i].v;
bug(v[i].v);
at[i] = i;
}
build(root);
bug(root->v, root->sum);
bug(root->lv, root->rv);
ll re = root->v;
vector<Ev> qu;
for (int i = 0; i<n; ++i) for (int j = i+1; j<n; ++j) {
if (v[i].y != v[j].y) {
qu.pb({-(v[i].x-v[j].x)/(double)(v[i].y-v[j].y), i, j});
}
}
sort(ALL(qu), [&](Ev a, Ev b){return a.sl < b.sl;});
for (Ev & e : qu) {
bug("swapping", e.a, e.b);
assert(abs(at[e.a]-at[e.b]) == 1);
MO(at[e.a], v[e.b].v, root);
MO(at[e.b], v[e.a].v, root);
swap(at[e.a], at[e.b]);
re = max(re, root->v);
}
cout<<re<<endl;
}
Compilation message
bulldozer.cpp: In function 'void MO(int, int, seg*&, int, int)':
bulldozer.cpp:54:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l+r>>1;
~^~
bulldozer.cpp: In function 'void build(seg*&, int, int)':
bulldozer.cpp:65:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l+r>>1;
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
516 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
8 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
7 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
640 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
7 ms |
640 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
640 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
516 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
8 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
7 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
640 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
7 ms |
640 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
640 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
33 |
Correct |
957 ms |
33732 KB |
Output is correct |
34 |
Correct |
955 ms |
33744 KB |
Output is correct |
35 |
Correct |
945 ms |
33728 KB |
Output is correct |
36 |
Correct |
974 ms |
33728 KB |
Output is correct |
37 |
Correct |
946 ms |
33616 KB |
Output is correct |
38 |
Correct |
980 ms |
33752 KB |
Output is correct |
39 |
Correct |
955 ms |
33888 KB |
Output is correct |
40 |
Correct |
960 ms |
33744 KB |
Output is correct |
41 |
Correct |
932 ms |
33744 KB |
Output is correct |
42 |
Correct |
947 ms |
33744 KB |
Output is correct |
43 |
Correct |
931 ms |
33752 KB |
Output is correct |
44 |
Correct |
967 ms |
33760 KB |
Output is correct |
45 |
Correct |
950 ms |
33748 KB |
Output is correct |
46 |
Correct |
936 ms |
33752 KB |
Output is correct |
47 |
Correct |
946 ms |
33744 KB |
Output is correct |
48 |
Correct |
949 ms |
33744 KB |
Output is correct |
49 |
Correct |
950 ms |
33768 KB |
Output is correct |
50 |
Correct |
957 ms |
33744 KB |
Output is correct |
51 |
Correct |
955 ms |
33756 KB |
Output is correct |
52 |
Correct |
950 ms |
33744 KB |
Output is correct |
53 |
Correct |
926 ms |
33744 KB |
Output is correct |
54 |
Correct |
943 ms |
33600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
516 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
8 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
7 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
640 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
7 ms |
640 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
640 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
33 |
Correct |
957 ms |
33732 KB |
Output is correct |
34 |
Correct |
955 ms |
33744 KB |
Output is correct |
35 |
Correct |
945 ms |
33728 KB |
Output is correct |
36 |
Correct |
974 ms |
33728 KB |
Output is correct |
37 |
Correct |
946 ms |
33616 KB |
Output is correct |
38 |
Correct |
980 ms |
33752 KB |
Output is correct |
39 |
Correct |
955 ms |
33888 KB |
Output is correct |
40 |
Correct |
960 ms |
33744 KB |
Output is correct |
41 |
Correct |
932 ms |
33744 KB |
Output is correct |
42 |
Correct |
947 ms |
33744 KB |
Output is correct |
43 |
Correct |
931 ms |
33752 KB |
Output is correct |
44 |
Correct |
967 ms |
33760 KB |
Output is correct |
45 |
Correct |
950 ms |
33748 KB |
Output is correct |
46 |
Correct |
936 ms |
33752 KB |
Output is correct |
47 |
Correct |
946 ms |
33744 KB |
Output is correct |
48 |
Correct |
949 ms |
33744 KB |
Output is correct |
49 |
Correct |
950 ms |
33768 KB |
Output is correct |
50 |
Correct |
957 ms |
33744 KB |
Output is correct |
51 |
Correct |
955 ms |
33756 KB |
Output is correct |
52 |
Correct |
950 ms |
33744 KB |
Output is correct |
53 |
Correct |
926 ms |
33744 KB |
Output is correct |
54 |
Correct |
943 ms |
33600 KB |
Output is correct |
55 |
Correct |
959 ms |
33744 KB |
Output is correct |
56 |
Correct |
985 ms |
33744 KB |
Output is correct |
57 |
Correct |
959 ms |
33768 KB |
Output is correct |
58 |
Correct |
959 ms |
33744 KB |
Output is correct |
59 |
Correct |
992 ms |
33760 KB |
Output is correct |
60 |
Correct |
957 ms |
33760 KB |
Output is correct |
61 |
Correct |
955 ms |
33744 KB |
Output is correct |
62 |
Correct |
965 ms |
33744 KB |
Output is correct |
63 |
Correct |
947 ms |
33744 KB |
Output is correct |
64 |
Correct |
958 ms |
33620 KB |
Output is correct |
65 |
Correct |
947 ms |
33760 KB |
Output is correct |
66 |
Correct |
950 ms |
33728 KB |
Output is correct |
67 |
Correct |
943 ms |
33760 KB |
Output is correct |
68 |
Correct |
955 ms |
33744 KB |
Output is correct |
69 |
Correct |
933 ms |
33744 KB |
Output is correct |
70 |
Correct |
958 ms |
33728 KB |
Output is correct |
71 |
Correct |
945 ms |
33748 KB |
Output is correct |
72 |
Correct |
958 ms |
33744 KB |
Output is correct |
73 |
Correct |
946 ms |
33632 KB |
Output is correct |
74 |
Correct |
949 ms |
33616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
516 KB |
Output is correct |
17 |
Correct |
6 ms |
640 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
6 ms |
512 KB |
Output is correct |
20 |
Correct |
6 ms |
512 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
8 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
512 KB |
Output is correct |
37 |
Correct |
6 ms |
512 KB |
Output is correct |
38 |
Correct |
7 ms |
512 KB |
Output is correct |
39 |
Correct |
6 ms |
512 KB |
Output is correct |
40 |
Correct |
6 ms |
512 KB |
Output is correct |
41 |
Correct |
6 ms |
512 KB |
Output is correct |
42 |
Correct |
6 ms |
640 KB |
Output is correct |
43 |
Correct |
6 ms |
512 KB |
Output is correct |
44 |
Correct |
7 ms |
640 KB |
Output is correct |
45 |
Correct |
6 ms |
512 KB |
Output is correct |
46 |
Correct |
6 ms |
640 KB |
Output is correct |
47 |
Correct |
6 ms |
512 KB |
Output is correct |
48 |
Correct |
957 ms |
33732 KB |
Output is correct |
49 |
Correct |
955 ms |
33744 KB |
Output is correct |
50 |
Correct |
945 ms |
33728 KB |
Output is correct |
51 |
Correct |
974 ms |
33728 KB |
Output is correct |
52 |
Correct |
946 ms |
33616 KB |
Output is correct |
53 |
Correct |
980 ms |
33752 KB |
Output is correct |
54 |
Correct |
955 ms |
33888 KB |
Output is correct |
55 |
Correct |
960 ms |
33744 KB |
Output is correct |
56 |
Correct |
932 ms |
33744 KB |
Output is correct |
57 |
Correct |
947 ms |
33744 KB |
Output is correct |
58 |
Correct |
931 ms |
33752 KB |
Output is correct |
59 |
Correct |
967 ms |
33760 KB |
Output is correct |
60 |
Correct |
950 ms |
33748 KB |
Output is correct |
61 |
Correct |
936 ms |
33752 KB |
Output is correct |
62 |
Correct |
946 ms |
33744 KB |
Output is correct |
63 |
Correct |
949 ms |
33744 KB |
Output is correct |
64 |
Correct |
950 ms |
33768 KB |
Output is correct |
65 |
Correct |
957 ms |
33744 KB |
Output is correct |
66 |
Correct |
955 ms |
33756 KB |
Output is correct |
67 |
Correct |
950 ms |
33744 KB |
Output is correct |
68 |
Correct |
926 ms |
33744 KB |
Output is correct |
69 |
Correct |
943 ms |
33600 KB |
Output is correct |
70 |
Correct |
959 ms |
33744 KB |
Output is correct |
71 |
Correct |
985 ms |
33744 KB |
Output is correct |
72 |
Correct |
959 ms |
33768 KB |
Output is correct |
73 |
Correct |
959 ms |
33744 KB |
Output is correct |
74 |
Correct |
992 ms |
33760 KB |
Output is correct |
75 |
Correct |
957 ms |
33760 KB |
Output is correct |
76 |
Correct |
955 ms |
33744 KB |
Output is correct |
77 |
Correct |
965 ms |
33744 KB |
Output is correct |
78 |
Correct |
947 ms |
33744 KB |
Output is correct |
79 |
Correct |
958 ms |
33620 KB |
Output is correct |
80 |
Correct |
947 ms |
33760 KB |
Output is correct |
81 |
Correct |
950 ms |
33728 KB |
Output is correct |
82 |
Correct |
943 ms |
33760 KB |
Output is correct |
83 |
Correct |
955 ms |
33744 KB |
Output is correct |
84 |
Correct |
933 ms |
33744 KB |
Output is correct |
85 |
Correct |
958 ms |
33728 KB |
Output is correct |
86 |
Correct |
945 ms |
33748 KB |
Output is correct |
87 |
Correct |
958 ms |
33744 KB |
Output is correct |
88 |
Correct |
946 ms |
33632 KB |
Output is correct |
89 |
Correct |
949 ms |
33616 KB |
Output is correct |
90 |
Correct |
960 ms |
33760 KB |
Output is correct |
91 |
Correct |
959 ms |
33744 KB |
Output is correct |
92 |
Correct |
960 ms |
33600 KB |
Output is correct |
93 |
Correct |
962 ms |
33744 KB |
Output is correct |
94 |
Correct |
968 ms |
33744 KB |
Output is correct |
95 |
Correct |
960 ms |
33732 KB |
Output is correct |
96 |
Correct |
950 ms |
33744 KB |
Output is correct |
97 |
Correct |
961 ms |
33768 KB |
Output is correct |
98 |
Correct |
972 ms |
33760 KB |
Output is correct |
99 |
Correct |
974 ms |
33744 KB |
Output is correct |
100 |
Runtime error |
390 ms |
64928 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
101 |
Halted |
0 ms |
0 KB |
- |