#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
#define assert(...)
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:21:0: warning: "assert" redefined
#define assert(...)
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from bulldozer.cpp:1:
/usr/include/assert.h:88:0: note: this is the location of the previous definition
# define assert(expr) \
bulldozer.cpp: In function 'void MO(int, int, seg*&, int, int)':
bulldozer.cpp:57:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l+r>>1;
~^~
bulldozer.cpp: In function 'void build(seg*&, int, int)':
bulldozer.cpp:68: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 |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 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 |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
768 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
640 KB |
Output is correct |
6 |
Correct |
6 ms |
640 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
640 KB |
Output is correct |
10 |
Correct |
6 ms |
640 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 |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 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 |
7 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
640 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 |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
512 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 |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
768 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
640 KB |
Output is correct |
6 |
Correct |
6 ms |
640 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
640 KB |
Output is correct |
10 |
Correct |
6 ms |
640 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 |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 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 |
7 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
640 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 |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
512 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 |
933 ms |
33748 KB |
Output is correct |
34 |
Correct |
938 ms |
33760 KB |
Output is correct |
35 |
Correct |
942 ms |
33744 KB |
Output is correct |
36 |
Correct |
960 ms |
33748 KB |
Output is correct |
37 |
Correct |
940 ms |
33740 KB |
Output is correct |
38 |
Correct |
945 ms |
33756 KB |
Output is correct |
39 |
Correct |
949 ms |
33728 KB |
Output is correct |
40 |
Correct |
952 ms |
33872 KB |
Output is correct |
41 |
Correct |
931 ms |
33620 KB |
Output is correct |
42 |
Correct |
949 ms |
33740 KB |
Output is correct |
43 |
Correct |
936 ms |
33616 KB |
Output is correct |
44 |
Correct |
939 ms |
33744 KB |
Output is correct |
45 |
Correct |
929 ms |
33740 KB |
Output is correct |
46 |
Correct |
939 ms |
33740 KB |
Output is correct |
47 |
Correct |
943 ms |
33768 KB |
Output is correct |
48 |
Correct |
951 ms |
33632 KB |
Output is correct |
49 |
Correct |
930 ms |
33632 KB |
Output is correct |
50 |
Correct |
960 ms |
33748 KB |
Output is correct |
51 |
Correct |
940 ms |
33744 KB |
Output is correct |
52 |
Correct |
931 ms |
33632 KB |
Output is correct |
53 |
Correct |
930 ms |
33748 KB |
Output is correct |
54 |
Correct |
941 ms |
33748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
768 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
640 KB |
Output is correct |
6 |
Correct |
6 ms |
640 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
640 KB |
Output is correct |
10 |
Correct |
6 ms |
640 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 |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 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 |
7 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
640 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 |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
512 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 |
933 ms |
33748 KB |
Output is correct |
34 |
Correct |
938 ms |
33760 KB |
Output is correct |
35 |
Correct |
942 ms |
33744 KB |
Output is correct |
36 |
Correct |
960 ms |
33748 KB |
Output is correct |
37 |
Correct |
940 ms |
33740 KB |
Output is correct |
38 |
Correct |
945 ms |
33756 KB |
Output is correct |
39 |
Correct |
949 ms |
33728 KB |
Output is correct |
40 |
Correct |
952 ms |
33872 KB |
Output is correct |
41 |
Correct |
931 ms |
33620 KB |
Output is correct |
42 |
Correct |
949 ms |
33740 KB |
Output is correct |
43 |
Correct |
936 ms |
33616 KB |
Output is correct |
44 |
Correct |
939 ms |
33744 KB |
Output is correct |
45 |
Correct |
929 ms |
33740 KB |
Output is correct |
46 |
Correct |
939 ms |
33740 KB |
Output is correct |
47 |
Correct |
943 ms |
33768 KB |
Output is correct |
48 |
Correct |
951 ms |
33632 KB |
Output is correct |
49 |
Correct |
930 ms |
33632 KB |
Output is correct |
50 |
Correct |
960 ms |
33748 KB |
Output is correct |
51 |
Correct |
940 ms |
33744 KB |
Output is correct |
52 |
Correct |
931 ms |
33632 KB |
Output is correct |
53 |
Correct |
930 ms |
33748 KB |
Output is correct |
54 |
Correct |
941 ms |
33748 KB |
Output is correct |
55 |
Correct |
935 ms |
33744 KB |
Output is correct |
56 |
Correct |
950 ms |
33756 KB |
Output is correct |
57 |
Correct |
948 ms |
33872 KB |
Output is correct |
58 |
Correct |
946 ms |
33744 KB |
Output is correct |
59 |
Correct |
957 ms |
33744 KB |
Output is correct |
60 |
Correct |
933 ms |
33632 KB |
Output is correct |
61 |
Correct |
947 ms |
33756 KB |
Output is correct |
62 |
Correct |
959 ms |
33620 KB |
Output is correct |
63 |
Correct |
958 ms |
33744 KB |
Output is correct |
64 |
Correct |
943 ms |
33616 KB |
Output is correct |
65 |
Correct |
947 ms |
33640 KB |
Output is correct |
66 |
Correct |
950 ms |
33744 KB |
Output is correct |
67 |
Correct |
955 ms |
33732 KB |
Output is correct |
68 |
Correct |
942 ms |
33752 KB |
Output is correct |
69 |
Correct |
953 ms |
33768 KB |
Output is correct |
70 |
Correct |
939 ms |
33740 KB |
Output is correct |
71 |
Correct |
944 ms |
33760 KB |
Output is correct |
72 |
Correct |
934 ms |
33744 KB |
Output is correct |
73 |
Correct |
948 ms |
33764 KB |
Output is correct |
74 |
Correct |
950 ms |
33760 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 |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 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 |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
640 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
768 KB |
Output is correct |
19 |
Correct |
6 ms |
640 KB |
Output is correct |
20 |
Correct |
6 ms |
640 KB |
Output is correct |
21 |
Correct |
6 ms |
640 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
6 ms |
640 KB |
Output is correct |
26 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 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 |
7 ms |
512 KB |
Output is correct |
38 |
Correct |
6 ms |
640 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 |
512 KB |
Output is correct |
43 |
Correct |
6 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
512 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 |
933 ms |
33748 KB |
Output is correct |
49 |
Correct |
938 ms |
33760 KB |
Output is correct |
50 |
Correct |
942 ms |
33744 KB |
Output is correct |
51 |
Correct |
960 ms |
33748 KB |
Output is correct |
52 |
Correct |
940 ms |
33740 KB |
Output is correct |
53 |
Correct |
945 ms |
33756 KB |
Output is correct |
54 |
Correct |
949 ms |
33728 KB |
Output is correct |
55 |
Correct |
952 ms |
33872 KB |
Output is correct |
56 |
Correct |
931 ms |
33620 KB |
Output is correct |
57 |
Correct |
949 ms |
33740 KB |
Output is correct |
58 |
Correct |
936 ms |
33616 KB |
Output is correct |
59 |
Correct |
939 ms |
33744 KB |
Output is correct |
60 |
Correct |
929 ms |
33740 KB |
Output is correct |
61 |
Correct |
939 ms |
33740 KB |
Output is correct |
62 |
Correct |
943 ms |
33768 KB |
Output is correct |
63 |
Correct |
951 ms |
33632 KB |
Output is correct |
64 |
Correct |
930 ms |
33632 KB |
Output is correct |
65 |
Correct |
960 ms |
33748 KB |
Output is correct |
66 |
Correct |
940 ms |
33744 KB |
Output is correct |
67 |
Correct |
931 ms |
33632 KB |
Output is correct |
68 |
Correct |
930 ms |
33748 KB |
Output is correct |
69 |
Correct |
941 ms |
33748 KB |
Output is correct |
70 |
Correct |
935 ms |
33744 KB |
Output is correct |
71 |
Correct |
950 ms |
33756 KB |
Output is correct |
72 |
Correct |
948 ms |
33872 KB |
Output is correct |
73 |
Correct |
946 ms |
33744 KB |
Output is correct |
74 |
Correct |
957 ms |
33744 KB |
Output is correct |
75 |
Correct |
933 ms |
33632 KB |
Output is correct |
76 |
Correct |
947 ms |
33756 KB |
Output is correct |
77 |
Correct |
959 ms |
33620 KB |
Output is correct |
78 |
Correct |
958 ms |
33744 KB |
Output is correct |
79 |
Correct |
943 ms |
33616 KB |
Output is correct |
80 |
Correct |
947 ms |
33640 KB |
Output is correct |
81 |
Correct |
950 ms |
33744 KB |
Output is correct |
82 |
Correct |
955 ms |
33732 KB |
Output is correct |
83 |
Correct |
942 ms |
33752 KB |
Output is correct |
84 |
Correct |
953 ms |
33768 KB |
Output is correct |
85 |
Correct |
939 ms |
33740 KB |
Output is correct |
86 |
Correct |
944 ms |
33760 KB |
Output is correct |
87 |
Correct |
934 ms |
33744 KB |
Output is correct |
88 |
Correct |
948 ms |
33764 KB |
Output is correct |
89 |
Correct |
950 ms |
33760 KB |
Output is correct |
90 |
Correct |
944 ms |
33888 KB |
Output is correct |
91 |
Correct |
927 ms |
33760 KB |
Output is correct |
92 |
Correct |
952 ms |
33928 KB |
Output is correct |
93 |
Correct |
969 ms |
33748 KB |
Output is correct |
94 |
Correct |
966 ms |
33632 KB |
Output is correct |
95 |
Correct |
939 ms |
33744 KB |
Output is correct |
96 |
Correct |
954 ms |
33616 KB |
Output is correct |
97 |
Correct |
949 ms |
33744 KB |
Output is correct |
98 |
Correct |
944 ms |
33760 KB |
Output is correct |
99 |
Correct |
949 ms |
33632 KB |
Output is correct |
100 |
Incorrect |
829 ms |
33616 KB |
Output isn't correct |
101 |
Halted |
0 ms |
0 KB |
- |